53

I recently installed Ubuntu 14.04, then I installed lamp-server and placed my webpages in /var/www directory, but when I opened localhost in the browser there was nothing. I think that happened because Zend updated Apache.

Whatever the reason may be, I want to know where to keep my php files so that I can access them from my browser.

Radu Rădeanu
  • 169,590
akxer
  • 2,036
  • Although not an answer to the OP's question, the following answer may help some visitors who stumble onto this question while trying to fix a related problem: http://askubuntu.com/a/525120/1183 – augustin Sep 17 '14 at 10:46

2 Answers2

79

The apache2 version that was published when the Ubuntu 14.04 release was made is 2.4.7 and starting with this version it seems that, for security reasons, the new root directory for the server is:

/var/www/html

So, from now on, this is where you must place the files for your (local) website. You should not have this problem again with the future updates.


Anyway, if you want to change this directory with another one, you have to modify (as root) the following line from /etc/apache2/sites-available/000-default.conf file (sudo nano /etc/apache2/sites-available/000-default.conf):

DocumentRoot /var/www/html

to

DocumentRoot /path/to/another/directory

After this, for the new changes to take effect, you have to restart the apache server using the following command:

sudo service apache2 restart
abu_bua
  • 10,783
Radu Rădeanu
  • 169,590
27

Instead of modifying /etc/apache2/sites-available/000-default.conf back to the old version, I prefer keeping default package files unmodified.

A reason for this is that so it wouldn't break during the next upgrade again which might reset the 000-default.conf file.
Besides, such modifications are not done just to annoy us, the modification was done for a good reason, as this bug report in Debian explains.

Our webservers [sic] set the default document root to /var/www, whereas site-local administrators tend to use /var/www/example.com. This has security implications if visitors access the default document root, bypassing the /supposed/ document root of example.com. That's problematic if sensitive data is placeѕ outside the supposed document root (e.g. consider a hypothetical /var/www/example-com-db.conf configuration file).

A better solution would be to move the sites files from /var/www to /var/www/html/.

# 1. move all files excluding the `html` directory
sudo mv /var/www/[!html]* /var/www/html
# 2. Move the hidden files as well which are skipped in previous command
sudo mv /var/www/.[!.]?* /var/www/html/

Also, another possible solution is to create another Virtual Host and disable the default one with the command sudo a2dissite 000-default

Dan
  • 13,119