0

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).

On Git

#!/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.

1 Answer 1

0

Maybe I don't understand when and why you use this script, but I don't see a reason why Magento should be in maintenance mode while you change the permissions. It's not like there will be inconsistencies if the shop keeps running or that anything is broken in between. So if you don't enable maintenance mode, there's nothing to worry about with the speed for the media directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.