Change Hosting, Domain Document Root for Laravel Project


How to Change Domain Document Root for Laravel ProjectWhen you purchase or create a Cpanel account and point a domain DNS to cpanel server, its often uses the "public_html" directory for all its websites files and data which is known as default Document Root, However when we deploy a Laravel Project to Cpanel Server, the sub directory "public_html/public" folder is occupied with website data and files that are available to general public, therefore we must change our domain default document root from public_html to public_html/public in order to ensure the Laravel project is successfully deployed.

The primary domain can also be setup to use a sub-directory inside public_html directory instead of public_html itself. Follow the below steps to change the default document root of your primary domain in cPanel account. Please note that, You must have root shell access for changing the main/primary domain document root in cPanel, Use following steps to change document root of your primary domain in cPanel account for Laravel Project.

Prerequisites
you must have root SSH access to perform these steps

Step 1 - Login to Cpanel Server where your Laravel Project is deployed

Connect to your server via SSH as root user.

Step 2 -  Update the Document Root

Using your favorite text editor (ex: nano) edit the following file.

nano /var/cpanel/userdata/USERNAME/DOMAINNAME.COM

Replace USERNAME with your cPanel account username and Replace DOMAINNAME.COM with your Primary domain name.

once you edited the file, find the following two lines in this file.

documentroot: /home/USERNAME/public_html
path: /home/USERNAME/public_html/cgi-bin

replace it with you Laravel Project Public Folder as below.

documentroot: /home/USERNAME/public_html/public
path: /home/USERNAME/public_html/public/cgi-bin

and then press CTRL+O to save the file, and then delete the cache file for your primary domain.

rm /var/cpanel/userdata/username/domain.com.cache

Step 3 - Update the Document Root for SSL 

 If the primary domain has an SSL certificate installed prior to change the document root as in step 2 above, you must edit the following file and do the changes as same as mentioned by the step 2

nano /var/cpanel/userdata/USERNAME/DOMAINNAME.COM_SSL

Save the file after changes are made and then delete the cache file for your primary SSL domain.

rm /var/cpanel/userdata/USERNAME/DOMAINNAME.COM_SSL.cache

Step 4 - Rebuild the Apache Configuration File

Run the following scripts to update the user data cache and rebuild apache configuration file.

/scripts/updateuserdatacache
/scripts/rebuildhttpdconf

Step 5 -  Restart the Apache server to reflect the changes

service httpd restart


If you have any other questions, experience or insights on "Changing Laravel Project Document Root from public_html to public_html/public folder" please feel free to leave your thoughts in the comments bellow which might be helpful to someone some day!.


Written by Akram Wahid 5 years ago

are you looking for a chief cook who can well craft laravel and vuejs, to make some awsome butterscotch,
yes then it is right time for you to look at my profile.

Do you want to write Response or Comment?

You must be a member of techalyst to proceed!

Continue with your Email ? Sign up / log in

Responses

Be the first one to write a response :(

{{ item.member.name }} - {{ item.created_at_human_readable }}

{{ reply.member.name }} - {{ reply.created_at_human_readable }}