Changing the document root for a primary domain involves modifying the configuration of a web server to specify a new directory as the root folder for serving files and content for that domain. By default, the document root points to a specific directory where the web server retrieves files to serve when a visitor accesses the domain. Changing the document root allows you to control which files and directories are accessible to visitors, enabling you to organize your website's content and structure as desired.
This document covers changing the document root for a primary domain on a VPS or dedicated server. On our shared hosting, the document root for the primary domain typically does not need to be modified. Reach out to our Technical Support team for a review.
Related Article
Modify Document Root for Addon Domain
Change Document Root for Primary Domain
IMPORTANT: This solution will require root access. If this needs to be obtained, follow the guide on requesting root access.
- SSH into the relevant server as root
- Edit
/var/cpanel/userdata/userna5/domain.com
using your text editor of choice
REPLACE: userna5 with the cPanel user and domain.com with the primary domain.
EXAMPLE:nano /var/cpanel/userdata/userna5/domain.com
- Change
documentroot: /home/userna5/public_html
todocumentroot: /home/userna5/new_doc_root_dir
REPLACE: userna5 with the cPanel user and new_doc_root_dir with the new document root. - Change
path: /home/userna5/public_html/cgi-bin
topath: /home/userna5/new_doc_root_dir/cgi-bin
REPLACE: userna5 with the cPanel user and new_doc_root_dir with the new document root.
EXAMPLE: The document root for imhkmc5 was updated from public_html to public_html/public, a common request for Laravel sites. - Save and exit the file
TIP: On nano, use <Ctrl+X> to save and exit. - Repeat Steps 2-5 on
/var/cpanel/userdata/userna5/domain.com_SSL
REPLACE: userna5 with the cPanel user and domain.com with the primary domain. - Rebuild Apache
/scripts/rebuildhttpdconf
- Restart Apache
/scripts/restartsrv_httpd --graceful
- If using PHP-FPM, edit
/var/cpanel/userdata/userna5/domain.com.php-fpm.yaml
REPLACE: userna5 with the cPanel user and domain.com with the domain.
- Change
php_admin_value_doc_root: /home/userna5/public_html
tophp_admin_value_doc_root: /home/userna5/new_doc_root_dir
REPLACE: userna5 with the cPanel user and new_doc_root_dir with the new document root.
NOTE: If the line does not exist, add it.
EXAMPLE: - Rebuild PHP-FPM
/scripts/php_fpm_config --rebuild
- Restart PHP-FPM
/scripts/restartsrv_apache_php_fpm
- Change
- If NGINX is installed
- Rebuild ngxconf
ngxconf -u userna5 -rdF && ngxutil -Xu userna5
REPLACE: userna5 with the cPanel username. - Restart NGINX
systemctl restart nginx
- Rebuild ngxconf
Comments
0 comments
Article is closed for comments.