Support Online
Skip to main content

Apache Web Root Migration Guide

In this guide, you will learn how to move Apache's default web root to a new storage.

What Will You Learn in This Guide?

  • How to find current DocumentRoot location
  • How to transfer files to new directory correctly
  • How to update Apache VirtualHost configurations
  • Test and restart Apache
  • Safely remove old directory

1. Finding Current Web Root Location

First, let's find where the DocumentRoot lines are in the active VirtualHost files.

grep -R "DocumentRoot" /etc/apache2/sites-enabled

This command lists all DocumentRoot paths used on active sites.

2. Copying Files to New Location

Example directories:

old location

/var/www/ornek.com

New target location

/mnt/harici_depolama

Let's transfer the files to the new location:

sudo rsync -av /var/www/ornek.com/ /mnt/harici_depolama

Description:

-a → protects permissions and ownership information. -v → shows detailed output. The / character at the end of the source directory allows the contents of the directory to be moved.

3. Updating the Apache HTTP VirtualHost File

Open HTTP configuration:

sudo nano /etc/apache2/sites-enabled/ornek.com.conf

Then edit as follows:

<VirtualHost *:80>
ServerAdmin admin@ornek.com
ServerName ornek.com
ServerAlias www.ornek.com

DocumentRoot /mnt/harici_depolama

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

<Directory /mnt/harici_depolama>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

The Directory block is required for Apache to access the new directory.

4. Updating SSL (HTTPS) VirtualHost File

Open HTTPS configuration:

sudo nano /etc/apache2/sites-enabled/ornek.com-le-ssl.conf

Update the DocumentRoot line:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@ornek.com
ServerName ornek.com
ServerAlias www.ornek.com

DocumentRoot /mnt/harici_depolama

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>

5. Testing and Restarting Apache Configuration

Let's check the configuration first:

sudo apachectl configtest

Expected output:

Syntax OK

Then reinstall Apache:

sudo systemctl reload apache2

6. Deleting the Old Web Root Directory

If the new directory works correctly, you can delete the old files:

sudo rm -Rf /var/www/ornek.com

This action cannot be undone.

Frequently Asked Questions (FAQ)

Can I use cp instead of rsync?

You can use it, but cp does not always carry all the permission and ownership information correctly. Therefore rsync -a is recommended.

Is the directory block mandatory?

Yes. Apache allows directory /var/www by default. It is necessary to define access for a different location.

Will the site broadcast be interrupted during the process?

Usually only a very brief outage occurs during Apache reload.

Is it safe to use an external disk as the new root directory?

It is secure and increases storage capacity as long as the correct permissions are given.

What happens if I don't edit the SSL configuration?

HTTP may work, but HTTPS will look in the old directory, which may result in a 404 or corrupted content error.

Result

With this guide, you have made your system more flexible, organized and scalable by moving the Apache web root directory to a new storage unit.

You can use the GenixNode platform to perform such server management operations faster.