Thursday, March 20, 2014

Drupal - access denied page after login

Today I got an access denied page after login, just rerooting me to the login page. I 've got this before, on a number of very different sites. Usually this problem coincides with big other problems in the website concerned, so you really can do without this annoying access problem.
There can be an infinite number of causes: Crashed sessions table, changes in apache, php upgrades, butterflies in Australia....
Here is my short track to quickly regain access to the site:

Solution 1
Truncate the sessions table and then try again

It is perfectly save to truncate the sessions table although all currently logged in users are then logged out.  The sessions table keeps track of all user sessions on your site. It has an entry for every user/browser combination that's logged in to your site. (Logging in from firefox and from chrome creates two entries in this table, and the same goes for logging in from different devices)

Solution 2
Add cookie domain setting to your settings.php file, like this
$cookie_domain = '.mydomain.ext';
And then try again

(see also

Solution 3
When your sessions table is crashed, simply repair table and try again

Solution 4
Find a religion that suits you bests and make an offering to the God or Gods who are proclaimed to be most helpful to developers by this chosen religion.....

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.

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

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.

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

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....