How to Change /home/tonyflor/domains/tonyteaches.tech/public_html Document Root in Apache

by

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

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 /home/test/ directory.

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.


About The Author

With a strong software engineering background, Tony is determined to help as many people as possible start their online busines. Discover why Tony quit his hedge fund job to pursue this mission. You can send Tony a message here.

2 thoughts on “How to Change /home/tonyflor/domains/tonyteaches.tech/public_html Document Root in Apache”

  1. I’m doing this on linux mint 19 for local development, And here is a problem am facing after following the steps.

    Forbidden

    You don’t have permission to access this resource.
    Apache/2.4.29 (Ubuntu) Server at 127.0.0.1 Port 80

    Reply
    • Hi Joe,

      This might be a permissions issue. Make sure that the “www-data” user and group owns all directories leading up to your new root. For example, you can do:
      sudo chown -R www-data:www-data /path/to/new/root
      sudo chown -R www-data:www-data /path/to/new
      sudo chown -R www-data:www-data /path/to

      Etc.

      Give that a try and let me know if it works for you.

      Reply

Leave a Comment