By default, Apache2 web server stores its documents in the /var/www/html directory on Ubuntu 17.04 / 17.10 systems. This is not a big deal for small sites or blogs. This may become a problem because this location on the root filesystem and may not be large enough for websites that are going rapidly.
When you website data is growing at a fast pace, you may find that the default root folder for Apache2 may not be adequate. You may have to move the root folder to a different and larger location to accommodate your content growth.
This brief tutorial is going to show students and new users how to move Apache2 default Document Root directory to a new location on Ubuntu 17.04 / 17.10.
To get started with migrating Apache2 document root folder, follow the steps below:
Step 1: Copy Apache2 DocumentRoot content
Again, Apache2 default DocumentRoot is at /var/www/html
Your goal is to change this default location to a new location with much higher free space. This is only useful if you’re running out of space at the default location..
This post assumes that you’ve already mounted or attached a large storage space to your system.. and that it’s mounted at /mnt/volume-mn1
The commands below will copy the entire html folder at /var/www/html and dump it into the new location at /mnt/volume-mn1
sudo rsync -av /var/www/html /mnt/volume-mn1
The new html folder will be at /mnt/volume-mn1/html
Step 2: Update Apache2 Configuration Files
Now that you’ve copied all the content from Apache2 default document root location, go and update Apache2 configuration files of the new location. By default, Apache2 site configuration files are stored in /etc/apache2/sites-available/ directory.
Run the commands below to open Apache2 default site config file.
sudo nano /etc/apache2/sites-available/000-default.conf
Then change the highlighted like to reflect the new DocumentRoot location
ServerAdmin webmaster@localhost DocumentRoot /mnt/volume-mn1/html Options FollowSymLinks AllowOverride None /mnt/volume-mn1/html> Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted
Save the file
Do this for all the site configuration files in the directory.. including the file below.
sudo nano /etc/apache2/sites-available/ssl-default.conf
ServerAdmin webmaster@localhost DocumentRoot /mnt/volume-mn1/html
Save the file
Step 3: Check and Restart Apahce2
Now that everything is setup, run the commands below to test Apache2 configuration
sudo apachectl configtest
If you get no error message, then run the commands below to reload the new settings.
sudo systemctl reload apache2.service
That’s it! Apache2 should begin using the new and larger location to retrieve its content.
You may also like the post below: