Skip to content

Instantly share code, notes, and snippets.

@Bodom78
Last active November 30, 2023 18:16
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Bodom78/9a6dd469fa0ed14e9c2a to your computer and use it in GitHub Desktop.
Save Bodom78/9a6dd469fa0ed14e9c2a to your computer and use it in GitHub Desktop.
WHM/cPanel - Changing an accounts document root

To properly edit an accounts DocumentRoot go to /var/cpanel/userdata/username/ (replace username with the actual cPanel username for the account), then edit the file domain.com (where domain.com is your primary domain name).

You will see something like this in that file:

documentroot: /home/username/public_html

You will also see the cgi-bin area in this section:

scriptalias:
  -
    path: /home/username/public_html/cgi-bin
    url: /cgi-bin/

Simply change both to the right path, then save the file. At that point, copy your existing httpd.conf file, rebuild Apache, then restart Apache. Your site will then start serving from the new document root.

Here are the commands to do those:

cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak02121014
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart

You can also look at /etc/httpd/conf/httpd.conf at that point to see it now has the changed DocumentRoot line and cgi-bin path.

@ahmedalmulki
Copy link

thanks , this worked for me , but the problem when I moved my website to https still pointing to public_html , how can I solve that ?

@kjdion84
Copy link

You need to do the same for /var/cpanel/userdata/username/domain.com_SSL

Just add _SSL to the end. Theres a separate file for SSL.

@AndreiTelteu
Copy link

@Bodom78 You can run command /scripts/updateuserdatacache before rebuildhttpdconf, to be sure that it does purge cache.
And instead of /etc/init.d/httpd restart, you can run /scripts/restartsrv_httpd. This is the recommended command for restart.
I found this here: https://forums.cpanel.net/threads/changing-document-root-for-primary-domain-does-not-work.626703/

So, the latest commands should be:

/scripts/updateuserdatacache
/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd

@tamkeen-tms
Copy link

@Bodom78
So this line cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak02121014 is just making a backup of the original config, right?

@Bodom78
Copy link
Author

Bodom78 commented Sep 2, 2019

@TamkeenLMS Correct, that command is just making a backup of the httpd.conf file.

It's been a while since I've looked into this so please refer to the comments about updating SSL and updated commands as well on this Gist.

@tamkeen-tms
Copy link

@Bodom78
Thanks, will do.

So, ... I am getting a "No input file specified." page, any idea what that should mean? I think it could be related to the cgi-bin directory or path?!

@Bodom78
Copy link
Author

Bodom78 commented Sep 4, 2019

@TamkeenLMS I'm not too sure, It could also be something to do with .htaccess and rewrite rules.

Just test a single index.php file in the new path to ensure it's working as expected and go from there.

@capobecchino
Copy link

@Bodom78
Thanks, will do.

So, ... I am getting a "No input file specified." page, any idea what that should mean? I think it could be related to the cgi-bin directory or path?!

Hei @TamkeenLMS try this command: /usr/local/cpanel/scripts/php_fpm_config --rebuild

@deguspice
Copy link

Hei @TamkeenLMS try this command: /usr/local/cpanel/scripts/php_fpm_config --rebuild

@capobecchino: Thank you, that fixed the "No input file specified."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment