• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, June 21, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Control Panels

How To Change The Apache Web Root To Another Directory on an Ubuntu 18.04 VPS or Dedicated Server

How VPS by How VPS
January 30, 2020
in Control Panels
0
How To Change The Apache Web Root To Another Directory on an Ubuntu 18.04 VPS or Dedicated Server
0
SHARES
192
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Introduction
  2. Start Here
    1. Step 1 – Transfer The File To A New Location
    2. Step 2 – Modifying Apache Config Files
    3. Step 3 – Implementing the Changes
  3. Conclusion

Introduction

By default, Apache archives its files in the directory /var/www/html on Ubuntu systems. This directory typically exists in a root filesystem; a location that also hosts other operating system files.  In some cases, it may be helpful to relocate your document roots to a different location.

This guide will show you how to move the Apache web root ( /var/www/html) to a different on your Ubuntu 18.04 system.

Ready? Let’s get started!

Start Here

To accomplish this task successfully, you need the following:

  • An SSL certificate for your own domain. This guide will use mydomain.com as our domain name. Remember to substitute this value with your unique domain name.
  • A unique location for document root directory. This guide will use /mnt/volume-ha1 as the unique location for the document root.

If everything is in place, let’s get started.

Step 1 – Transfer The File To A New Location

As aforementioned, Apache Web Server uses /var/www/html as the location for the document root. Also, by implementing the prerequisite instructions, you fashioned a document root called /var/www/mydomain.com/html. This should be your main document root, but you can have other document roots located in the corresponding Apache VirtualHost directives.

Our aim here is to pinpoint the exact location of the document roots, then transfer their corresponding files to the new directory. Since we want to limit our search to only the active websites, we’ll search for the locations in the directory /etc/apache2/sites-enabled using grep. First, execute the command below to search the locations:

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

The -R enables grep to display the full file name and the document root in the output, as shown below:

/etc/apache2/sites-enabled/mydomain.com-le-ssl.conf:  DocumentRoot /var/www/mydomain.com/html
/etc/apache2/sites-enabled/mydomain.com.conf:         DocumentRoot /var/www/mydomain.com/html

The output above may differ depending on your underlying setups. Regardless of the results, it should be easy to determine if you are relocating the correct files and that you are updating the desired config files.

Once, you confirm the exact location of the document root, use rsync to copy its existing files to the new location. Execute the command below:

$ sudo rsync -av /var/www/mydomain.com/html /mnt/volume-ha1

The command features an -a flag which ensures the directory properties and permissions are preserved during the file transfer. In addition, the command features a -v flag, which delivers the verbose output to help you monitor how the synchronization progresses. This will give you an output similar to the one below:

sending incremental filelist
html/
html/index.html

sent 318 bytes  received 39 bytes  714.00 bytes/sec
total size is 176  speedup is 0.49

By now, the files are in their new location and it’s time to modify Apache web server configuration to rhyme with the above changes.

Step 2 – Modifying Apache Config Files

Apache web server is built to utilize site-specific and global config files. As a result, our configuration cannot reflect the changes made unless we modify the /etc/apache2/sites-enabled/mydomain.com.conf, which is the VirtualHost configuration file for our domain (mydomain.com).

We should also modify /etc/apache2/sites-enabled/mydomain.com-le-ssl.conf; a configuration file created when the SSL certs for our domain were configured.

Note: The files we are about to modify, are the config files displayed in step one after running the grep command.

First, execute the command below to open the first configuration file:

$ sudo nano /etc/apache2/sites-enabled/mydomain.com.conf

This will give you an output with file’s content. Find a line beginning with DocumentRoot. Update the value of this line with /mnt/volume-ha1/html; which is our new location for document root. Once you update that line, you should have the following:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /mnt/volume-ha1/html
    ErrorLog${APACHE_LOG_DIR}/error.log
    CustomLog${APACHE_LOG_DIR}/access.log combined
RewriteEngineon
RewriteCond%{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond%{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Next, add the directive below to this configuration file to enable the server to follow the symlinks in the new directory.

. . .
<Directory /mnt/volume-nyc3-01/html>
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

Point to remember: You should monitor the DocumentRoot as displayed in Step 1 after executing the grep command. Also, ensure the DocumentRoot in rewrites or aliases is updated to reflect the changes in the new location for the document root.

Once that is done, run the command below to open your SSL configuration file:

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

Update the DocumentRoot with /mnt/volume-ha1/html; the new location for document root. Make sure you have the following after the update:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /mnt/volume-ha1/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
. . .
</VirtualHost>
</IfModule>

That is it! You have modified both config files and they are now reflecting the new document root location.

Step 3 – Implementing the Changes

Now that you all the changes in place, you can easily restart your Apache service and confirm the results. But first, run the command below to confirm the syntax:

$ sudo apachectl configtest

This will give you an output similar to the one below:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

To deactivate that top line, include a unique ServerName directive (your IP address or Server’s Domain) to /etc/apache2/apache2.conf.

Now, execute the command below to restart your Apache service:

$ sudo systemctl reload apache2

Once the service restarts, visit your websites and check if everything is functioning as expected. If everything is fine, run the command below to delete the native files of the sites’ data.

$ sudo rm -Rf /var/www/mydomain.com/html

Conclusion

You have successfully moved the document root for your Apache web server to a different location.

Previous Post

How To Enable mod_evasive To Log & Report DOS Attack And BruteForce Attack On Apache

Next Post

How to install Zabbix on CentOS 7

Next Post
How to install Zabbix on CentOS 7

How to install Zabbix on CentOS 7

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In