Currently, when I want to reset Magento permissions to ensure security, I execute the following from the root of my Magento project (planning on moving it to ./shell).
#!/bin/bash
#This is designed to work with 'apache' as the file owner and 'webroot' as the assigned group.
touch maintenance.flag
if [ ! -f ./app/etc/local.xml ]; then
echo "-- ERROR"
echo "-- This doesn't look like a Magento install. Please make sure"
echo "-- that you are running this from the Magento main doc root dir"
exit
fi
if [ `id -u` != 0 ]; then
echo "-- ERROR"
echo "-- This script should be run as root so that file ownership"
echo "-- changes can be set correctly"
exit
fi
echo "1/8 Setting all files to owner apache and group webroot"
chown -R apache:webroot .
echo "2/8 Magento didn't seem to like SELinux. Patching that up..."
sudo chcon -R -t httpd_sys_rw_content_t .
chmod -R a+w .
#is this next line the same as the lines above?
chmod g+s -R .
echo "3/8 Setting all files to 470 (Apache read access and webroot group read/write/execute)..."
find . -type f -exec chmod 2470 {} \;
echo "4/8 Setting all directories to 570 (Apache read/execute access and webroot group read/write/execute)..."
find . -type d -exec chmod 2570 {} \;
echo "5/8 Setting var and media files to 670 (Apache read/execute access and webroot group read/write/execute)..."
find var/ -type f -exec chmod 2770 {} \;
find media/ -type f -exec chmod 2670 {} \;
chmod -R 2770 sitemap;
echo "6/8 Making modules directory and files writable for extendware extension..."
chmod -R 2770 app/etc
echo "7/8 Setting var and media directories to 770 (Apache read/write/execute access and webroot group read/write/execute)..."
find var/ -type d -exec chmod 2770 {} \;
find media/ -type d -exec chmod 2770 {} \;
echo "8/8 Securing all .htaccess files..."
find . -name ".htaccess" -exec chmod 2440 {} \;
echo "Protecting some directories."
chmod 2070 -R ./downloader
chmod 2070 -R ./.git
echo "Removing Maintenance.flag"
rm maintenance.flag
##If Fishpig WordPress installed
echo "reseting wordpress"
cd wp
sh resetWpPermissions.sh
This does the job, but with my image directory included in the reset, it takes a couple of minutes sometimes. That is a few minutes with the maintenance.flag file enabled.
I'm hoping that someone can "learn me" in how to make this more efficient or point me to an alternative solution to keeping Magento permissions static.