Where to place my local website starting with the 2.4.7 version of apache2?

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

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

Tags:

Lamp

Apache2