How does Drupal find contributed modules and themes? I have a development site with a peculiar problem  Although the contributed modules and themes are in their proper place under sites/all/modules (&amp; 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) &amp;&amp; $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.
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.