In this quick tutorial, you’ll learn how to change the default Apache document root from /home/tonyflor/domains/tonyteaches.tech/public_html to something else. This requires you to have root access to your server. If you have that, let’s jump into the tutorial.
Change Apache DocumentRoot
DocumentRoot allows you to specify a different location to host your Apache website. By default, DocumentRoot is set to /home/tonyflor/domains/tonyteaches.tech/public_html. You can see this for yourself by looking at the configuration file for your website at
/etc/apache2/sites-available/ and ending in *.conf.
However, for whatever reason you want to change this to another location on your server. For this example, let’s say we want to host a website from the
The best way to demonstrate this is with a new Apache configuration file. Create a file at
/etc/apache2/sites-available/ called test.conf and paste the following code.
<VirtualHost *:80> <Directory /home/test/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> DocumentRoot /home/test </VirtualHost>
The most important line in the code above is the DocumentRoot line. This line sets the Apache document root for the website to the
/home/test/ directory. The block of code between the Directory tags simply enables directory listings in Apache and is safe to ignore if you are not following this tutorial verbatim.
If you are following the tutorial, disable all other websites with
a2dissite * and enable the test configuration with the
a2ensite test.conf command.
When you have made the necessary changes, restart the apache service with
service apache2 restart or similar.
If you did everything correctly, you how have a website or listing that is served out of a directory other than /home/tonyflor/domains/tonyteaches.tech/public_html!
Please let me know below if you have any questions about changing the document root in Apache.