Jump to content

How to move Apache's Root Direcotry to a new location

Recommended Posts



By default on Ubuntu the Apache2 web server stores its files in "/var/www/html" folder. Sometimes it’s helpful to move it to another location, such as a separate mounted file system and so on.

In this tutorial you will learn how to move the default directory to a new location. We are using Ubuntu 16.04 for this tutorial, however you should be able to follow this guide using any of our offered Ubuntu or Debian distributions.

Copying Files

We are using "rsync" for coping files to a new location:

rsync -av /var/www/html /new/location

Where "-a" flag preserves the permissions and other directory properties and "-v" flag provides comprehensive output.

Note: If you are using "Tab" completion be sure to delete trailing slash "/" on the the directory.

Updating The Configuration File

Now we need to update "000-default.conf" file:

nano /etc/apache2/sites-enabled/000-default.conf

Now we will find the line that begins with "DocumentRoot" and update it with the new location. It should look something like this:

# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /nauja/direktorija

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Restarting Apache

Once you’ve finished the configuration changes, you can make sure the syntax is right with "configtest":

apachectl configtest

If everything is right you should get result:

Syntax OK

As long as you get Syntax OK, restart the web server. Otherwise, track down and fix the problems it reported. Use the following command to restart Apache:

systemctl reload apache2


That's it! You changed Apache's default folder and from know all your affected sites will be loaded from new location.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...