By default, the Apache web server stores its documents in the /var/www/html document root directory, which is located on the root filesystem. In this section, we will learn how to move this directory to the new mounted filesystem we configured previously.
Connect to the EC2 instance that you created earlier as you did in the Logging in section.
First, change your directory to the root directory:
cd /
We want to move the document root directory’s content from /var/www/html to the new mount point directory /data.
Copy the document root directory’s content to the new location using rsync:
sudo rsync -av /var/www/html /data
Next, we need to modify Apache server’s configuration file and make it use the new directory.
Open and edit the configuration file:
It is a good practice to create a backup of the known good configuration file before making edits. Some critical files (such as /etc/fstab) can prevent the system from booting properly if there are typos or incorrect configuration.
sudo nano /etc/httpd/conf/httpd.conf
In the document, find this section:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"
#
# Relax access to content within /var/www.
#
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
Modify DocumentRoot and Directory “/var/www/html” to use the new location:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/data/html"
#
# Relax access to content within /var/www.
#
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/data/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
Save the file. Now, let’s test that the Apache server is actually configured to use the new location for its document root directory.
Remove the index.html file you created before:
sudo rm /var/www/html/index.html
Refresh your web browser. Your web site will not show your custom index.html homepage. We need to restart the Apache server in order to use apply the new configuration.
Restart the Apache server:
sudo systemctl restart httpd
Refresh again your browser. Your web site will be up and running. The Apache server uses the new location for its document root directory.
Congratulations! You’ve finished the Linux Workshop! Make sure to update the class roster to show your progress.
The next step is to clean up your account – rmeove the instance and the EBS volume to avoid any charges.