
Introduction
On Ubuntu, Apache2 web server's default document root is _/var/www/html_
. If you need to move this directory to a different location, such as a separate mounted filesystem, this guide will show you how to do so. This tutorial uses Ubuntu 16.04, but the steps are applicable to other Ubuntu and Debian versions as well.
Copying Files
To move the Apache document root to a new location, use the rsync
command:
rsync -av /var/www/html /new/location
The -a
flag preserves permissions and attributes, while -v
provides verbose output. If you use tab completion, ensure that you remove the trailing slash /
from the directory path.
Updating the Configuration File
Update the Apache configuration file to point to the new document root location:
nano /etc/apache2/sites-enabled/000-default.conf
Locate the DocumentRoot
line and change it to the new path:
DocumentRoot /new/location
Save and close the file.
Restarting Apache
After updating the configuration, verify the syntax with:
apachectl configtest
You should see Syntax OK
. If the syntax is correct, restart Apache to apply the changes:
systemctl reload apache2
Conclusion
You have successfully moved Apache’s default document root to a new location. All your sites will now be served from this updated path.