Last active
February 20, 2024 09:47
-
-
Save drubb/c784e7f1f18db544f1ad4926036854c4 to your computer and use it in GitHub Desktop.
Simple script to fix file and directory permissions in Composer based Drupal installation. Suitable if web server and CLI user are members of the same group.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Exit the script if any statement returns a non-true return value. | |
set -e | |
# Goto the project root using Drush | |
root="$(drush dd)" | |
cd "$root" | |
cd .. | |
# Set all permissions to 755 for directories and 644 for files | |
# in the root directory and all subdirectories. | |
find . -type d -exec chmod 755 {} \; | |
find . -type f -exec chmod 644 {} \; | |
# Set the permissions for the files and directories that need to be writable. | |
find private -type d -exec chmod 775 {} \; | |
find private -type f -exec chmod 664 {} \; | |
find web/sites/default/files -type d -exec chmod 775 {} \; | |
find web/sites/default/files -type f -exec chmod 664 {} \; | |
# Special: composer.json and composer.lock should have directory permissions. | |
chmod 755 composer.json | |
chmod 755 composer.lock | |
# Make binaries in the vendor/bin directory executable. | |
chmod +x vendor/bin/* | |
# Do the same with all node binaries in the theme folder. | |
chmod +x web/themes/custom/my_theme/node_modules/.bin/* | |
# Make all scripts in the scripts directory executable. Remove this if not needed. | |
chmod +x scripts/*.sh | |
# Remove all .htaccess files in public and private files directories. | |
find web/sites/default/files -name .htaccess -exec rm {} \; | |
find private -name .htaccess -exec rm {} \; | |
# Recreate those .htaccess files and fix permissions for settings files. | |
drush rq --quiet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment