I have a development site with a peculiar problem Although the contributed modules and themes are in their proper place under sites/all/modules (& themes) I am getting an error message that says that my custom theme cannot be found. Also, the modules list does not include any of the contributed modules.

The error message indicates that it does not find my default theme:

Notice: Undefined index: CR_Stark in drupal_theme_initialize() (line 100 of /example.com/includes/theme.inc). Notice: Trying to get property of non-object in _drupal_theme_initialize() (line 145 of /example.com/includes/theme.inc).

While I would assume that the relative locations of these custom directories is hard coded in Drupal core, the fact that it cannot find the modules when they are in the correct place suggests that there may be a missing variable or setting. I have checked the sites/default/settings.php file and looked through the variables table in the database, but cannot find a reference that would serve this purpose. Can anyone point me in the right direction?

EDITS: per suggestions in comments:

  • Caches have been cleared frequently without change

  • Changing to a default theme removes the theme error, but it is replaced with an error I believe is tied to not knowing where the custom modules are.

Warning: opendir(sites/all/modules): failed to open dir: Permission denied in file_scan_directory() (line 2034 of example.com/includes/file.inc).

Line 2034 is in the core function file_scan_directory () and reads if (is_dir($dir) && $handle = opendir($dir)) {; so it looks like Drupal is searching for a custom module (or theme) directory it cannot find or access. The directory access settings are correct.

  • The directory settings in the systems table are correct and the contributed modules and theme are all included.

This may not be the solution, but it is one resolution, of a sort.

I recreated the site from scratch with a new core install and copied all of the contents of the sites/all/... directories to the new site. I then imported the entire database from the affected site into the new one and ran update/php. This new site is seeing everything fine. These dev sites are being run on a virtual box running Ubuntu. It may have had something to do with settings on the directories from the OS, but I could not find it.

If anyone else has had a similar problem and found a source for the problem, please post it here.

  • Have you tried switching back to a core theme? Are all your module in the list if/when you do that?
    – Chapabu
    Apr 3, 2012 at 13:16
  • 2
    Have you tried clearing the cache, that often helps with this sort of thing?
    – Clive
    Apr 3, 2012 at 13:18
  • 1
    What does system table say ? does it point to proper DIR path ? All themes & modules related paths are stored in system table
    – GoodSp33d
    Apr 3, 2012 at 13:22
  • I'm wondering if the theme has a base theme that's not actually there. I'm sure I've seen this error before...
    – Chapabu
    Apr 3, 2012 at 13:29
  • 1
    @Ashlar the error you've got suggests your access permissions for the directory are definitely not correct. Your web server user is unable to open 'sites/all/modules' for reading. What are the POSIX permissions on that folder?
    – Clive
    Apr 3, 2012 at 14:30

3 Answers 3


Based on the error message you are getting, "failed to open dir: Permission denied in file_scan_directory()," I would assume that directory access settings are in fact not correct. The user running your webserver can apparently not open sites/all/modules. The best way to check this is to actually switch to the user running the webserver and try to open the directory. A common example would be a user named "apache" for the apache httpd.

On a Linux/OSX system one would often run the following command to accomplish this, though it could vary if your distribution already has a default shell for the user, or supplies a different one from bash. The example is from ubuntu, assuming you are using a normal user account with sudo privileges.

sudo su apache -s /bin/bash

How to do this in Windows I don't know, though I assume it's possible.

  • 2
    To add to what reported in this answer, file_scan_directory() is called from drupal_system_listing(), and it is never called for directories that don't exist.
    – apaderno
    Apr 3, 2012 at 14:36
  • I am running a vbox on Windows 7 using Ubuntu, although I am new to linux. I used quickstart to set it up. Where do I find the name for the user running the server?
    – Ashlar
    Apr 3, 2012 at 14:48
  • apache will be the user perhaps
    – GoodSp33d
    Apr 3, 2012 at 14:54
  • 1
    In ubuntu it's 'www-data' by default
    – Letharion
    Apr 3, 2012 at 20:58

To see what ownership files and directories have, is the ls command: ls -l To change them, use chown as root: sudo chown ... or su -c chown ... use the man command for fuller details: man 1 chown man 1 ls

In some distributions, notably RHEL and its clones, selinux also has a vote. Such errors might be logged in /var/log/messages or an audit file. Note, if selinux gets in the way, turning it off is seriously stupid. Fix the access and policy rules.


Letharion was correct, but implementing the solution required a bit of nuance. I am using Ubuntu Linux on a vbox. The various themes and modules were placed on this development site by copying them over from another site. Apparently the settings for owner and access to the directories and files were either changed when copying them to this site (they had worked fine on the other site). To change the permissions required that the terminal be opened with the correct user name (you can verify the name of the user for the terminal by entering the command WhoamI). I then had to make certain that the files and directories were owned by the Group 'www-data' which is the identity used by Apache. In order to change the group owning the files I used the command sudo chgrp -R www-data directory-path The -R tells the command to iterate through any subdirectories below the directory path. The command to change permissions is sudo chmod -R ### directory-path. The three # represent three numbers. that define permissions for the owner, the group and others respectively. To assign a number for each add the values for each setting. Thus read = 2, write = 4, and execute = 1. To give all three powers the proper number would be 2+4+1=7.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.