After drupal update site throws HTTP ERROR 500

409 views Asked by At

I updated drupal from 9.2.7 to latest version using composer. The update was completed but the site throws "This site currently unable to handle this request.HTTP ERROR 500" I changed the owner as "sudo chown -R username:groupname <drupal_directory>" with backup's username and password. But no use. I applied "chmod 755 -R <drupal_directory>" and the site loaded. But am getting permission errors when I tried a new update with composer. I am sure this problem is because of permission but what is the proper way to fix this problem?

2

There are 2 answers

1
Balde Binos On

Generally, I create some bash script so that I can run it every time I run some updates or make any change to the Drupal installation.

The script may be something like:

#!/bin/bash

# site directory
site_directory="/path/to/drupal/installation" # full path to drupal installation

# user and group
user_name="user_name" # root is a good choice
group_name="group_name" # nginx, www-data, apache, etc., depending on the installed web server 

# reset user and group
chown -R ${user_name}:${group_name} ${site_directory}/

# reset general permitions
find ${site_directory} -type d -exec chmod u=rwx,g=rx,o= '{}' \;
find ${site_directory} -type f -exec chmod u=rw,g=r,o= '{}' \;

# reset files permitions
find ${site_directory}/web/sites/default/files/ -type d -exec chmod ug=rwx,o= '{}' \;
find ${site_directory}/web/sites/default/files/ -type f -exec chmod ug=rw,o= '{}' \;

# reset general selinux context (comment if not running selinux)
chcon -R system_u:object_r:httpd_sys_content_t:s0 ${site_directory}/

# reset files selinux context (comment if not running selinux)
chcon -R -t httpd_sys_rw_content_t ${site_directory}/web/sites/default/files/

Of course, clearing the caches is also a good idea.

1
Balde Binos On

Yes. The above script, sets permissions in a, somewhat, restrictive way.

Namely, I feel uncomfortable, setting execute permissions to drush.

Any time I need to run drush, I specifically set execution permissions to drush:

cd /path/to/drupal/installation
chmod 700 vendor/bin/drush

Then, I can run the necessary drush commands.

If You find this tedious, just add:

chmod 700 ${site_base_directory}/vendor/bin/drush

at the end of the script above.