LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Recursively fixing FTP ownership on a Plesk managed web server (https://www.linuxquestions.org/questions/linux-server-73/recursively-fixing-ftp-ownership-on-a-plesk-managed-web-server-795657/)

bahbahthelamb 03-15-2010 10:47 PM

Recursively fixing FTP ownership on a Plesk managed web server
 
I made the mistake of running chown -R 775 /var/www/vhosts instead of chmod -R 775 /var/www/vhosts and in a short blink, all the sites started throwing HTTP 403s. So I wrote this php-based shell script to fix the issue. I figured that I would post it here in case someone else needs it:
Code:

#!/usr/bin/php
<?php
$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 s.login from sys_users s where s.home='/var/www/vhosts/".$site."';");
        if ($result = mysql_fetch_array ($r)) {
                shell_exec ("chown -R ".$result[0]." /var/www/vhosts/".$site);
                print "Owner of /var/www/vhosts/".$site." has been updated to ".$result[0]."\n";
        }
}
mysql_close ();
?>

I'm sure there is even a simpler method, but this method at least works.


All times are GMT -5. The time now is 12:27 AM.