Bash script to correct public_html file permissions to run with suphp+suexec

pcsousa

Well-Known Member
May 28, 2004
63
0
156
After install suphp, I found many sites not running because file permissions wrong.

I made a bash script to correct those permissions:

if [ -z "$1" ]
then
echo "use: change.perms cpanel_user";
exit;
fi

# Load up your home directories...
HomeDirectories[0]="/home/$1"
HomeDirectories[1]="/home2/$1"
# add more if needbe
# HomeDirectories[2]="/home3/$1"

# Setup find correctly...
export IFS=$'\n'

# Loop through our array...
for x in ${HomeDirectories[@]}
do
if [ -h "$x" ]; then
# Prevent repeat because of links on different home directories ...
echo "Leaving $x because is symlink..."
else
# Find all Dirs
z="$x/public_html"
for i in $( find $z -type d )
do
# Fix Permissions
if [ "$z" != "$i" ]
then
# Do not change public_html directory itself perms...
chmod -c 755 $i
chown -c $1:$1 $i
fi
done

# Find all Files
for i in $( find $z -type f )
do
# Fix Permissions
chmod -c 644 $i
chown -c $1:$1 $i
done

# Make configure.php and configuration.php files non writable to avoid Joomla and osCommerce warning...
for i in $( find $z -type f |grep configure.php)
do
# Fix Permissions
chmod -c 444 $i
done
for i in $( find $z -type f |grep configuration.php)
do
# Fix Permissions
chmod -c 444 $i
done
fi
done
echo "Done."
Feel free to comment, post upgrades and correct any part.

Regards.