Skip to content

Instantly share code, notes, and snippets.

@aamnah
Last active September 8, 2022 15:23
Show Gist options
  • Select an option

  • Save aamnah/eff1c13f8b8d893c7c61 to your computer and use it in GitHub Desktop.

Select an option

Save aamnah/eff1c13f8b8d893c7c61 to your computer and use it in GitHub Desktop.
Opencart Secure Permissions (after install)
# delete install folder
if [ -d "install/" ]; then
rm -rf install
fi
# To change all the directories to 755 (-rwxr-xr-x)
find . -type d -exec chmod 755 {} \;
# To change all the files to 644 (-rw-r--r--):
find . -type f -exec chmod 644 {} \;
# set 444 for admin files
chmod 444 config.php
chmod 444 admin/config.php
chmod 444 index.php
chmod 444 admin/index.php
chmod 444 system/startup.php
# set 777 for cache
chmod 777 image/cache/
chmod 777 system/cache/
# delete install folder
if [ -d "install/" ]; then
rm -rf install
fi
# To change all the directories to 755 (-rwxr-xr-x)
find . -type d -exec chmod 755 {} \;
# To change all the files to 644 (-rw-r--r--):
find . -type f -exec chmod 644 {} \;
# set 444 for admin files
chmod 444 config.php
chmod 444 admin/config.php
chmod 444 index.php
chmod 444 admin/index.php
chmod 444 system/startup.php
# set 777 for cache
chmod 777 image/cache/
chmod 777 system/storage/cache/
@MathiasReker
Copy link
Copy Markdown

Nice script. Thanks for sharing. :-)
I would like to share a library I have coded with the same goal.

Example of usage:

<?php

use MathiasReker\PhpChmod\Scanner;

require __DIR__ . '/vendor/autoload.php';

(new Scanner())
    ->setDefaultFileMode(0644)
    ->setDefaultDirectoryMode(0755)
    ->setExcludedFileModes([0400, 0444, 0640])
    ->setExcludedDirectoryModes([0750])
    ->scan([__DIR__])
    ->fix();

Full documentation: https://github.com/MathiasReker/php-chmod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment