On an Apache HTTP Server, you can control where the server looks for live HTML documents; in other words, your web pages or content management system. Most web-based control panels set this up for you by default when virtual hosts are created, and changing the panel’s settings could very well break your system.
But if you are not running a control panel or are only running a single website on your dedicated server, you may want to have your HTML documents in a custom directory of your choice. The default documents directory depends on the Linux distribution. Common default locations are /var/www, /var/www/html, /home/user/www/html, /home/user/public_html, /home/user/www/htdocs, and many others.
To change your Apache installation’s document root, enter the following in your apache configuration file (which is usually /etc/httpd/httpd.conf or /etc/apache2/httpd.conf):
Replace “directory-path” with the actual path to the directory you want to use. For example, you could use:
Make sure you do not use a trailling slash in the path. With the above configuration, the index.html file at /var/www/public_html/index.html will appear on the web as http://www.yourdomain.com/index.html. Finally, make sure the directory you set as the document directory is readable but not writable to outside users.
For virtual hosts, you may want to set a custom document root for a particular website, while maintaining the default settings for all other sites. To do this, you will need to locate the virtual host’s configuration file. It may be something like /var/www/vhosts/domain.com/conf/vhosts.conf, depending on your server’s configuration. Edit that file, and add the same DocumentRoot directive.
After you have edited the necessary files, save them and restart apache:
apachectl -k restart