The DocumentRoot is the folder of your website that is accessed when navigating to your website's domain name. When using a web hosting package, the /www/ folder will be set as the default DocumentRoot of your website. This means that, when you visit your domain name, the contents of the /www/ folder is served. The folders and files inside the DocumentRoot are publically accessible. Folders and files outside of the DocumentRoot are not.
Suppose you've set the folder /public/ inside your /www/ folder as the DocumentRoot. As a result, the contents of the /public/ folder will be displayed when visiting your domain name. The other files and folders located in the /www/ folder cannot be accessed publicly and are only used for the configuration of your website. To a degree, these files and folders will be protected from the outside.
Changing the DocumentRoot
Take note: The option to change the DocumentRoot was added for our more advanced users. For this reason we recommend only changing the DocumentRoot if you're familiar with it.
In order to change the DocumentRoot of the website on your web hosting package, you will first need to log in to your control panel. Now head over to the tab 'Domains & Hosting' at the top of the page.
Next, select your domain name on the left hand side (don't check the box). On the right hand side, click on 'Manage' followed by 'Document Root'.
On the next page you can see that the default value is being used, which means the /www/ folder is used as the DocumentRoot. To configure a different DocumentRoot, set the slider to 'Off'.
Now you can enter the name of the folder you want to set as the DocumentRoot and click 'Change' to save your changes.
The folder you set as the DocumentRoot here is always located in the /www/ folder. In the example above our DocumentRoot will become the /www/public/ folder.
To configure a folder within a folder as the DocumentRoot, add a ' / ' between the folders. In the example below the folder /www/public/site/ is set as the DocumentRoot.
Applications for the DocumentRoot
Configuring a different DocumentRoot than the /www/ folder is recommended if you want to host a Laravel or Magento2 website on your web hosting package. As a rule, you will want to keep files for these types of website outside of the DocumentRoot.
You can either use /www/ or a folder inside /www/ as the DocumentRoot. If /www/ is your DocumentRoot, all the files and folders inside /www/ will be visible.
Because you will want to keep certain files for Laravel and Magento2 websites hidden, it's important to set a folder inside /www/ as the DocumentRoot. That way the files and folders present in that specific folder will be accessed when visiting the website's domain name. All the other files and folders inside /www/ will not be publicly accessible; they are solely used for the configuration of your website.
Take a look at the article 'Using SFTP filemanagement in your control panel' for more information on managing the files and folders of your website via the control panel.
In this article we discussed using and configuring the DocumentRoot for websites hosted on a web hosting package.
If you have any questions regarding this article, please contact our support team. You can reach them using the 'Contact us' button below or via the 'Contact' button inside your control panel.
If you wish to discuss this article with other users, feel free to leave a comment below.