Thursday, March 20, 2014

Drupal - unable to overwrite the settings.php

The funny thing about drupal is it protects your files and permissions automatically. But sometimes I feel like a pilot in a plane where I do not know some of the automation.
For instance, sometimes you want to overwrite the settings.php file and you do not have the permissions as the FTP user. Here is first a simple set of steps how to proceed.

Problem: 
You want to make changes to settings.php but are not allowed to overwrite.

Cause:
Drupal automatically sets the following permissions on your default folder and on your settings.php therein

dr-xr-xr-x 3 {user} {group} 4096 Mar 20 12:31 default
-r-xr-xr-x  1 {user} {group} 10516 Mar 20 10:27 settings.php


The user being your ftp user then is not allowed to write into the default folder, nor to overwrite the settings.php file.
Which is good, of course, but we temporarily want to be bad.


Solution:
What you want is to change the permissions, overwrite settings.php, and then reset the permissions to what they where.

1. login to your server shell and navigate to your site
cd /var/www/vhosts/domain.ext/sites
2. change the permissions of the default folder
sudo chmod a+w default
3. enter the default directory
cd default
4. change permissions of your settings.php (oooow, spooky...)
sudo chmod 777 settings.php
5. Now overwrite the settings.php with your FTP program.6. To restore the permissions of the default folder and the settings.php file just login to your site, go to administer -> reports -> status report

admin/reports/status
7. running ls -l in your terminal will show you that all permissions are magically restored. Hail Drupal.

Step 6 is maybe like a braindead way of restoring the permissions, but it is the good way of doing this, let drupal handle this stuff, and you point your brain to problems that are interesting on a human level....



No comments:

Post a Comment