Skip to main content

File Permissions (Cheatsheet for Linux setups)

These are a few notes regarding file permissions on Linux platforms.

A good thread on Drupal file and directory settings is here,
Paths to private files in Drupal 9.

project
    /config
    /web
        /themes
        /sites
        /profiles
        /modules
       PACKAGE_MANAGER_FAILURE.yml // The reason for this page; it was a rabbit hole. 
    /tmp
    /vendor
    /private
-------------
// Optional folders as needed
    /backup
    /scripts
    /log

// Backing the site files
> tar cfz backups/{date}-root.tgz config drush-scripts private_files scripts vendor web 
// Backing the database
sudo cat ../web/sites/default/settings.php
Dump: mysqldump -u dbadmin -p drupal_database > db_drupal_database_{date}.sql
Load: mysql -u  -p < db_{name}_{date}.sql

Image
Traffic


sudo chown -R admin_user:www-data /path/to/drupal
sudo chown -R www-data:{ username here } /var/www/html

sudo find /var/www/lol_system -user { username here }
sudo find /var/www/lol_system/cms -type d  -exec chown www-data:www-data {} \;

sudo find /path/to/drupal -type d -exec chmod g+s {} \;
sudo find /var/www/html -type d -exec chmod g+s {} \;

chmod g+w: Adds the group write permission (g+w) without modifying other existing permissions (like execute).

 chmod g+s:  The s in the permissions (e.g., drwxrwsr-x) refers to the Set Group ID (SGID) bit for directories. When the SGID bit is set on a directory, it ensures that:

- Any files or subdirectories created within the directory will automatically inherit the same group as the parent directory, rather than the primary group of the user who creates them.

- This is especially useful in collaborative environments, such as when multiple users are working on a Drupal site and the web server group (www-data) needs consistent group ownership.

Before applying SGID:
drwxrwxr-x  2 admin_user www-data 4096 Jan 22 04:33 js
After applying SGID:
drwxrwsr-x  2 admin_user www-data 4096 Jan 22 04:33 js

sudo find /path/to/drupal -type d -exec chmod 775 {} \;
sudo find /var/www/(project) -type d -exec chmod 775 {} \;

sudo find /path/to/drupal -type f -exec chmod 664 {} \;
sudo find /var/www/(project) -type f -exec chmod 664 {} \;

Update ~/.bashrc :
umask 002
 

Image
File Permissions

 

:/var/www/( project name )/cms/web/sites/default$ cp default.services.yml services.yml
:/var/www/( [project name )/cms/web/sites/default$ cp default.settings.php settings.php
 

-rw-r--r-- 1 user_name   www-data 10656 Jan 20 12:48 services.yml
-rw-r--r-- 1 user_name   www-data 36406 Jan 20 12:56 settings.php 

Add Trusted Host to the settings.php

$settings['trusted_host_patterns'] = [
 '^example\.com$',
 'example\.lol$'
];

Image
Success with Drupal CMS
Failed update detected
"Staged changes failed to apply, and the site is in an indeterminate state. It is strongly recommended to restore the code and database from a backup. Caused by PhpTuf\ComposerStager .... "

When the Drupal Package Manager fails, a YML error file is generated. Fix the error, then remove the file. 
Image
TIL / Package Manager Error