3

After creating new accounts via WHM I find that all folders created in the public_html folder have a permission of 775 which often leads to a 500 error in a browser.

I am currently executing the following command via SSH find . -type d -exec chmod 755 {} \; from the public_html folder for every new account that I create on my VPS.

How can I set the default permissions for new files/folders VPS-wide so that I don't have to SSH in and run that command every tyime I create a new account on my VPS?

Solid I
  • 580
  • 5
  • 13
  • 34

2 Answers2

2

First, you must put a ticket to WHM/Cpanel because that behavior is not correct. When WHM create a new account always create with 755 permissions public_html

But workaround using post and pre script hooks.

  • Create a file /usr/local/cpanel/scripts/postwwwacct
  • This file run after /usr/local/cpanel/scripts/postwwwacct (each time that the system creates a cPanel account)
  • chmod 755 /usr/local/cpanel/scripts/postwwwacct

Content of /usr/local/cpanel/scripts/postwwwacct

#!/usr/bin/php -q

// Set up our variables to be usable by PHP
$opts = array();
$argv0 = array_shift($argv);

while(count($argv)) {
    $key = array_shift($argv);
    $value = array_shift($argv);
    $opts[$key] = $value;
}


exec("chmod 755 {$opts['homedir']}/public_html");

This correct your /home/{user}/public_html to 755

You can use doc on cpanel Although the documentation of Cpanel and its broken links are quite deficient, which causes that google finds much information of copy and paste of bad quality.

abkrim
  • 3,512
  • 7
  • 43
  • 69
  • I didn't think this was correct behavior, I will contact the hosting company that setup this WHM/cPanel instance and have them fix this at the source, but your workaround is a nice quick fix! I'll be trying that in the morning. Thank you! – Solid I Nov 28 '16 at 17:55
  • In order to stop the workaround from executing, so I simply add a `#` before `exec("chmod 755 {$opts['homedir']}/public_html");`? – Solid I Nov 28 '16 at 17:56
  • I put on my post, error it's on correo of WHM. That it's a workaorund. For stop, delete file /usr/local/cpanel/scripts/postwwwacct. It is a optional file. Read doc. – abkrim Nov 29 '16 at 06:28
  • This answer doesn't solve my problem. `exec("chmod 755 {$opts['homedir']}/public_html");` will only chmod existing directories. When I create a new folder, it's still 775. – Solid I Nov 29 '16 at 22:09
  • This is a valuable answer, just not to my question. I'd suggest adding -R to the command to make the chmod recursive to all directories within public_html. – Solid I Nov 29 '16 at 22:10
  • On you question ask about specific problem: `public_html`not about other folders.Now the question it's " I create a new folder, it's still 775"? Please open new question. – abkrim Nov 30 '16 at 19:05
  • About -R ... same.. your question it's about one folder on one process: create account. On create account, only folders on skeleton on root are created. You are confusing – abkrim Nov 30 '16 at 19:06
-2

The folks over at the cPanel Forum helped me get to the bottom of this.

Turns out that this behavior happens when using connection protocol SFTP. I've changed the connection protocol to FTP and all new folders are now created with 755 permissions.

I hope this helps someone!

Solid I
  • 580
  • 5
  • 13
  • 34
  • I voted negative, because the answer is not to your own question. On the other hand I think it is showing a series of answers and questions in the comments that far from helping muddle the knowledge of Cpanel. The answer that says talks about how you connect after you have created the account, and the question is about the permissions when you create a new account.. I think you should read the documentation of Cpanel and of course the Stackoverflow – abkrim Nov 30 '16 at 19:10