Select Page


On Ubuntu, the Apache web server shops its paperwork in /var/www/html, which is usually situated at the root filesystem with remainder of the working gadget. Now and again, even though, it’s useful to transport the file root to some other location, comparable to a separate fastened filesystem. As an example, if you happen to serve more than one internet sites from the similar Apache example, hanging every web site’s file root by itself quantity permits you to scale according to the wishes of a selected web site or consumer.

On this information, you’re going to transfer an Apache file root to a brand new location.

Must haves

To finish this information, you’re going to want:

  • An Ubuntu 18.04 server and a non-root consumer with sudo privileges. You’ll be able to be informed extra about how you can arrange a consumer with those privileges in our Initial Server Setup with Ubuntu 18.04 information.
  • Apache put in, following How To Install the Apache Web Server on Ubuntu 18.04.
  • SSL configured on your area following How To Secure Apache with Let’s Encrypt on Ubuntu 18.04. We can use the area identify on this educational, however you will have to replace this with your personal area identify.
  • A brand new location on your file root. On this educational, we will be able to use the /mnt/volume-nyc3-01 listing for our new location. In case you are the use of Block Garage on DigitalOcean, this guide will display you how you can create and connect your quantity. Your new file root location is configurable according to your wishes, then again. In case you are shifting your file root to another garage software, it would be best to make a choice a location underneath the software’s mount level.

Step 1 — Copying Information to the New Location

On a recent set up of Apache, the file root is situated at /var/www/html. Via following the prerequisite guides, then again, you created a brand new file root, /var/www/ You might also have further file roots in corresponding VirtualHost directives. On this step, we will be able to determine the positioning of our file roots and duplicate the related information to their new location.

You’ll be able to seek for the positioning of your file roots the use of grep. Let’s seek within the /and so on/apache2/sites-enabled listing to restrict our center of attention to lively websites. The -R flag guarantees that grep will print each the DocumentRoot and the whole filename in its output:

  • grep -R "DocumentRoot" /and so on/apache2/sites-enabled

If you happen to adopted the prerequisite tutorials on a recent server, the outcome will seem like this:


/and so on/apache2/sites-enabled/ DocumentRoot /var/www/ /and so on/apache2/sites-enabled/ DocumentRoot /var/www/

If in case you have pre-existing setups, your effects would possibly fluctuate from what is proven right here. In both case, you’ll use the comments from grep to remember to’re shifting the required information and updating the best configuration information.

Now that you have showed the positioning of your file root, you’ll replica the information to their new location with rsync. The use of the -a flag preserves the permissions and different listing houses, whilst -v supplies verbose output so you’ll apply the growth of the sync:

Notice: Be certain there’s no trailing slash at the listing, that may be added if you happen to use tab finishing touch. When there’s a trailing slash, rsync will sell off the contents of the listing into the mount level as an alternative of moving it right into a containing html listing.

  • sudo rsync -av /var/www/ /mnt/volume-nyc3-01

You’ll see output like the next:


sending incremental document listing html/ html/index.html despatched 318 bytes won 39 bytes 714.00 bytes/sec overall dimension is 176 speedup is 0.49

With our information in position, let’s transfer directly to enhancing our Apache configuration to replicate those adjustments.

Step 2 — Updating the Configuration Information

Apache uses each international and site-specific configuration information. For background concerning the hierarchy of configuration information, check out How To Configure the Apache Web Server on an Ubuntu or Debian VPS. We can alter the virtual host files for our project: /and so on/apache2/sites-enabled/ and /and so on/apache2/sites-enabled/, which was once created once we configured SSL certificates for

Notice: Take into account that to your case will probably be your_domain_name, and that you are going to be enhancing the digital host information that have been outputted while you ran the grep command in Step 1.

Get started via opening /and so on/apache2/sites-enabled/

  • sudo nano /and so on/apache2/sites-enabled/

In finding the road that starts with DocumentRoot and replace it with the brand new root location. In our case this will probably be /mnt/volume-nyc3-01/html:

/and so on/apache2/sites-enabled/

    ServerAdmin sammy@instance.comn
    DocumentRoot /mnt/volume-nyc3-01/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/get entry to.log blended
RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Let’s additionally upload directives to make sure that the server will apply the symbolic hyperlinks within the listing:

/and so on/apache2/sites-enabled/

. . .

    Choices FollowSymLinks
    AllowOverride None
    Require all granted

Stay an eye fixed out for the DocumentRoot that grep outputted in Step 1, together with in aliases or rewrites. You’ll additionally wish to replace those to replicate the brand new file root location.

After saving those adjustments, let’s flip our consideration to the SSL configuration. Open /and so on/apache2/sites-enabled/

  • sudo nano /and so on/apache2/sites-enabled/

Regulate the DocumentRoot to replicate the brand new location, /mnt/volume-nyc3-01/html:

/and so on/apache2/sites-enabled/

    DocumentRoot /mnt/volume-nyc3-01/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/get entry to.log blended
. . .

You’ve got now made the essential configuration adjustments to replicate the brand new location of your file root.

Step 3 — Restarting Apache

Whenever you’ve completed making the configuration adjustments, you’ll restart Apache and take a look at the consequences.

First, make certain the syntax is correct with configtest:

  • sudo apachectl configtest

On a recent set up you’re going to get comments that appears like this:


AH00558: apache2: May no longer reliably decide the server's totally certified area identify, the use of Set the 'ServerName' directive globally to suppress this message Syntax OK

If you wish to suppress the highest line, simply upload a ServerName directive for your primary (international) Apache configuration document at /and so on/apache2/apache2.conf. The ServerName will also be your server’s area or IP deal with. That is only a message, then again, and does not impact the capability of your web site. So long as the output accommodates Syntax OK, you are prepared to proceed.

Use the next command to restart Apache:

  • sudo systemctl reload apache2

When the server has restarted, discuss with your affected websites and make sure that they’re operating as anticipated. Whenever you’re relaxed that the whole lot is so as, don’t disregard to take away the unique copies of the information:

  • sudo rm -Rf /var/www/

You’ve got now effectively moved your Apache file root to a brand new location.


On this educational, we lined how you can exchange the Apache file root to a brand new location. This mean you can with elementary internet server management, like successfully website hosting more than one websites on a unmarried server. It additionally permits you to profit from choice garage units comparable to community block garage, which will also be useful in scaling a internet web site as its wishes exchange.

If you happen to’re managing a hectic or rising internet web site, you could be keen on studying how to load test your web server to spot efficiency bottlenecks prior to you stumble upon them in manufacturing. You’ll be able to additionally be informed extra about bettering the manufacturing enjoy on this comparability of five ways to improve your production web application server setup.