Just try chmod 000 settings.php and Drupal will throw "Unsupported database type". I spent 20 minutes debugging this. I think there should be much better error message.

Comments

danbh’s picture

I can confirm this error.

dries’s picture

How come your Drupal files had no read permissions set? Was that due to an FTP upload?

(This looks like a rare scenario to me -- therefore I'd like to understand what caused this.)

meba’s picture

Priority: Critical » Normal

Sure. Personally, I did chmod 640 settings.php which made settings.php unreadable. It's rarely, but it deserves better error message i think (I spent 30 minutes debugging). Dropping priority to normal, this is not critical i think...

zoo33’s picture

StatusFileSize
new1.05 KB

The same happens if for some reason settings.php is not present. The error message that catches the problem (described above) is not exactly helpful, although I agree that this should be a very rare problem.

Anyway, here is a patch against HEAD that adds a check to config_init() in bootstrap.inc and gives a more suitable error message. I have tested it quickly and it seems to work fine.

zoo33’s picture

Status: Active » Needs review

Needs review. I don't have an opinion about whether this has a critical or normal priority.

ChrisKennedy’s picture

This is normal priority as it's a rare case. I also ran into this issue when debugging the installation system, and have proposed an alternative solution at http://drupal.org/node/101829 which also attempts to make the file readable (i.e. if the web server owns settings.php).

ChrisKennedy’s picture

StatusFileSize
new4.17 KB

Here's what I came up with from the other bug report, it's a slightly different technique compared to #4.

This patch modifies bootstrap.inc to not assume that settings.php is readable, and attempts to set the readable bit for settings.php if it's unreadable. It displays a correct error message if no settings.php file exists or if the file exists but isn't readable - previously there would be several warning messages and then an error about an unsupported database type. It fixes drupal_verify_install_file() to check that the file exists before attempting to check any of the other masks - before it resulted in a php stat error in drupal_install_fix_file() because fileperms() requires the file to exist.

ChrisKennedy’s picture

StatusFileSize
new4.09 KB

All this talk about optimization made me realize that instead of wasting a stat() via is_readable() for a very rare situation (settings.php is unreadable or doesn't exist), we should just add a @ to include_once() in bootstrap.inc. It's run on every page so I think this is preferable.

forngren’s picture

It works like a charm for me, as long as I chmod it to 400, when I try 000 I get the following error:

Fatal error: Unknown function: file_directory_path() in /.../includes/common.inc on line 1429

But I'm not sure if that is possible to fix.

Btw; small string offset against head. Nice patch =)

ChrisKennedy’s picture

Version: 5.0-beta2 » 5.x-dev
StatusFileSize
new4.1 KB

Re-rolled against head.

@forngren - I tried it with 000 and didn't get an error. In any case this patch is an improvement imo.

forngren’s picture

I still gets the same error, but I'm pretty sure my host is causing that :( It's impossible to make a patch like this one to work on 'all' installations

Someone else will have to review this one or I'll will do it when I am coming across another server setup. You will need someone else to review it anyway, cause I would not dare to RTBC this patch, I'm still to junior.

dries’s picture

-  include_once './'. conf_path() .'/settings.php';
+  @include_once './'. conf_path() . '/settings.php';

Is that @ required? It's considered ugly in the World of Drupal. ;-)

ChrisKennedy’s picture

Status: Needs review » Needs work

IMO we should either use an @ or put the include_once in an if (is_readable()) block if we want to handle the (rare) case of settings.php not being readable, otherwise there will be an error.

In #8 I thought that using an @ might be a slight optimization over is_readable and switched, so we can either switch back to is_readable or I can add a comment to explain the @. I see that I need to remove that extra space for the string concatenation too.

ChrisKennedy’s picture

Status: Needs work » Needs review
StatusFileSize
new4.63 KB

Okay, I realized that there also needed to be a check for db_url within conf_init() and added it, only later seeing that zoo33 had included the same check in the original patch. This includes a more specific error message by testing whether the settings.php is unreadable or doesn't exist.

@forngren: I was able to get the same error and fix it by modifying drupal_maintenance_theme() to include file.inc. It's needed due to the drupal_add_css() but there is at least one execution path in which it isn't included beforehand. This is fixed in the updated patch.

ChrisKennedy’s picture

Title: Unsupported database type when settings.php unreadable » Accurate error messages for install and bootstrap
Component: database system » base system

Clearer title.

RobRoy’s picture

#10 fixed my dupe issue at http://drupal.org/node/105697.

ChrisKennedy’s picture

StatusFileSize
new4.39 KB

Re-rolling with file.inc change removed, as this was fixed individually by http://drupal.org/node/102599

dries’s picture

The proposed patch is bit clunky so I'm not going to commit this yet / as is. Maybe we can come up with a slightly more elegant approach.

ChrisKennedy’s picture

Title: Accurate error messages for install and bootstrap » Accurate error message when settings unreadable
StatusFileSize
new2.81 KB

Updated version removes the use of @, which is slow, and checks the return value of include_once rather than checking if db_url isset.

I also removed the changes to drupal_verify_install_file(), which aren't entirely needed and will be posted separately (with some improvements).

ChrisKennedy’s picture

Any more suggestions on this?

ChrisKennedy’s picture

Assigned: Unassigned » ChrisKennedy
ChrisKennedy’s picture

Version: 5.x-dev » 6.x-dev

Sorry, one more minor change.

dries’s picture

Chris, when you said "one minor change", did you intend to attach a new patch?

Looking at the code, I wonder if it wouldn't be better to make this more transparent and to explicit checks. Rather than relying on include_once to throw an error, maybe we can simply call file_exists() before doing the include_once?

Or better, yet, maybe conf_path() should not return an invalid settings file. conf_path() already does a bunch of file_exists() so we could one more ... Assuming that we'll /fix/ conf_path(), we'd now be able to write:

  if ($settings = conf_path()) {
    // ...
  }
  else {
    // No settings file found.
  }

To me, that looks like a more elegant approach. Thoughts?

ChrisKennedy’s picture

StatusFileSize
new2.78 KB

Okay I changed it to use explicit checks rather than waiting for include_once to throw an error.

conf_path() returns a directory, not a settings file, so it can't really be modified. Plus we want it to return the directory even if the settings file is unreadable, because we may be able to chmod it (drupal_verify_install_file() tries to do this).

ChrisKennedy’s picture

Status: Needs review » Needs work

Needs to be re-rolled due to bootstrap.inc changes.

pancho’s picture

Important bugfix, that still needs to be done.

meba’s picture

Status: Needs work » Postponed (maintainer needs more info)

I don't think this is still too important. D6 introduced sites/default as a writable directory, so users no longer need to change settings.php directly. This bug can appear only if default.settings.php is unreadable, which is really rare.

I can reroll the patch, but I am not sure it's worth it. Anyone else?

pancho’s picture

Good point by meba. I'm still moving this to D7 and let others decide whether this would be a won't fix.

pancho’s picture

Version: 6.x-dev » 7.x-dev

Ehm, here we go...

sun.core’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Sorry, without further information this issue can only be marked as won't fix.

Feel free to re-open this issue if you want to provide further information. Thanks.