PHP Script to fix plesk domains ownership

php-scriptcPanel comes default with lots of inbuilt script to do multiple tasks. But in case of plesk most of the task like fixing permission and ownership etc has to be done manually. It can easily be done for one or two accounts but it will be very time consuming and irritating when you have to do it for the whole server. Generally incorrect user ownership issues are occured while we are migrating the server by using the rsync command or restoring the server from the crashed hard drive to the new hard drive. To resolve the ownership issue you will need to ssh to server as root and create a file fixpleskownership.php and set it’s permission to 755. After than run the script and it will do the dirty work for you

$sites = explode ("\n", trim (shell_exec ("ls /var/www/vhosts")));
mysql_connect ("localhost", "admin", shell_exec ("cat /etc/psa/.psa.shadow"));
mysql_select_db ("psa");
foreach ($sites as $site) {
$r = mysql_query ("select login from sys_users where home='/var/www/vhosts/".$site."';");
if ($result = mysql_fetch_array ($r)) {
shell_exec ("chown -R ".$result[0]." /var/www/vhosts/".$site);
print "Ownership of /var/www/vhosts/".$site." has been updated to ".$result[0]."\n";
mysql_close ();

Server Management Plus can manage your plesk server under our plesk server management plan.


Sreejit is the founder of Server Management Plus. His motto is "If there's an easier way, Why do it any other way" and following it, he has created a lots of automation scripts for the company using which we are able to resolve issue at an extremely fast rate and save lots of time. He has a very keen interest in new technologies and spend most of his free time online researching about it apart from listening music and watching movies.