Last updated on September 21st, 2021 at 10:55 am
When you migrate website to a different location, you need to change document root path of Apache server so that it can serve requests from the new location. Let’s take a look at how to move Apache web root to new location in Ubuntu and other Debian systems. You can also use it to change Apache document root directory in CentOS and other RPM based systems.
How To Move Apache Web Root to a New Location on Ubuntu 18.04
By default, Apache stores website’s files & directories at /var/www/html . First, we will move the website content to new location, and then update Apache server’s virtual host files to point Apache to this new location.
After you move Apache web root to new location, you may want to use a reporting tool to monitor the key metrics about your website/application such as signups, traffic, sales, revenue, etc. using dashboards & charts, to ensure everything is working well and spot issues quickly.
1. Transfer website content to new location
If you are using Apache’s default configuration, all your website content will be at /var/www/html. If you have setup a different Document root (e.g /var/www/example.com/html) then you will need to transfer that directory to new location. For our example, we will go with the default configuration.
Let’s say you want to move Apache web root to new location /mnt/website. So run the following command to move your website folders & files to new location.
$ sudo rsync -av /var/www/html /mnt/website
After this, you will find html folder at /mnt/website as /mnt/website/html
Bonus Read: How to Disable Apache Directory Listing
2. Update Apache configuration file
Open the Virtual host configuration file located at /etc/apache2/sites-available/
Apache’s default virtual host configuration file at the above location is 000-default.conf or default.conf, depending on your Linux system. If you have created a different virtual host file (e.g /etc/apache2/sites-available/example.conf) then open that file
$ sudo vi /etc/apache2/sites-available/000-default.conf
Now look for the line that begins with DocumentRoot. It will look something like
DocumentRoot /var/www/html
Here, change the path of your web root from /var/www/html to /mnt/website/html. So it will look like
DocumentRoot /mnt/website/html
Bonus Read : How to Configure Apache Cache
3. Restart Apache Server
Now test Apache config
$ sudo apachectl configtest
If you get no error, restart Apache server
-------- On SystemD based systems -------- $ sudo systemctl restart apache2 $ sudo systemctl restart httpd -------- On SysVInit based systems -------- $ sudo /etc/init.d/apache2 restart $ sudo /etc/init.d/httpd restart
That’s it! Now you can move Apache web root to new location using above steps.
That’s it! Now you can move Apache web root to new location using above steps. By the way, if you want to create charts & dashboards to monitor your business or website, you can try Ubiq. We offer a 14-day free trial.
Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI & software development.