简体   繁体   中英

why is it that info.php only work if placed in /var/www/html not /var/www/?

I have just deployed LAMP in preparation for Elgg installation. After I deployed apache and php I wanted to test my progress by creating info.php file. I placed the file in /var/www/ and tried to visit it from the browser only to get an error:

Not Found

The requested URL /info.php was not found on this server.

Apache/2.4.7 (Ubuntu) Server at 192.168.0.9 Port 80

when I placed the same exact file in /var/www/html it worked and displayed the Apache and php installation settings. Can anyone please explain to me why? for educational purposes.

Apache webserver will show documents that are put to a specific location. Root of that location is referred as document root.

For example, if DocumentRoot were set to /var/www/html then a request for http://www.yoursite.com/folder1/yourpage.php would result in the file /var/www/html/folder1/yourpage.php being served to the requesting client

In ubuntu default location is /var/www for server root and on Centos its /var/www/html

This change requires a service restart.

you can change this from /etc/httpd.conf where there is a section about document root.

But again on your distro which is ubuntu its under /etc/apache2/http.conf

Debian based systems

ServerRoot              ::      /etc/apache2
DocumentRoot            ::      /var/www
Apache Config Files     ::      /etc/apache2/apache2.conf
                        ::      /etc/apache2/ports.conf
Default VHost Config    ::      /etc/apache2/sites-available/default,/etc/apache2/sites-enabled/000-default
Module Locations        ::      /etc/apache2/mods-available, /etc/apache2/mods-enabled
ErrorLog                ::      /var/log/apache2/error.log
AccessLog               ::      /var/log/apache2/access.log
cgi-bin                 ::      /usr/lib/cgi-bin
binaries (apachectl)    ::      /usr/sbin
start/stop              ::      /etc/init.d/apache2 (start|stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean)

Because /var/www/html is the default document root path of your apache. You can edit the path in /etc/apache2/sites-available/default.conf You may. Find the DocumentRoot as

/var/www/html

在此处输入图片说明

Default DocumentRoot of apache is /var/www/html. Edit your httpd.conf config file located in /etc/apache2 directory and change DocumentRoot to /var/www

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM