I recently moved a module from one location to another location and I am getting a ClassNotFoundException
. Is there something similar to Registry Rebuild Module that can help rebuild the registry?
6 Answers
In addition to the usual cache rebuild, the additional need to restart the web server is due to a decision in Drupal 8 to be 'fast by default' use the APC Classloader if it is available. It is faster, but it doesn't necessarily catch changes as you make them. To not have to restart your web server during development, you can set your local environment to not try to use a better-for-production class loader.
For instance, in local.settings.php add:
$settings['class_loader_auto_detect'] = FALSE;
Via, and more background information at, what to do when developing a Drupal 8 module and a class file just isn't being loaded even though it is definitely there.
-
2
-
-
Worked for me. Afterwards, I could remove this line and it still works.– ArlaJan 12, 2022 at 12:58
In Drupal 8 the equivalent of Registry Rebuild is built in to Cache Rebuild. If your site is not accessible you will need to use Drush. Its an indispensable tool in D8 for just this reason.
drush cr
-
If you don't have access to drush, which is definitely the easiest option, then you can also use rebuild.php after enabling it in settings.php. Drupal 8 has no class registry, but class names with their namespace are often stored somewhere, for example form and controller classes are stored in the router table, so you need to rebuild that.– BerdirApr 6, 2015 at 16:58
"drush cr" may not always work. You may have to restart your Web server to pick up new file locations. This is due to some caching at that level.
I recently got this issue of "class not found" with a custom module. The strange thing is that this problem occurred in a multi-sites installation after installation of new site on server. But the issue never pop-up before with other sites with same modules and configuration. Thus it is very strange. I tried all sort of cache clearing, composer updates, restarts and so on. Also tried to replicate the installation on local computer and it worked fine in this case.
I really can't figure out what could be the explanation and why it happens specifically on a "sub" site and not on the others.
The only solution I could implement is for this particular setting is
$settings['class_loader_auto_detect'] = FALSE;
which is working but does not bring any clue on the issue.
Any idea on the direction to look for is welcome. Thanks
The easiest solution could be visiting www.yoursite.com/core/install.php
location on your website.
If that doesn't solve your problem take a look at https://www.drupal.org/documentation/rebuild for further debugging which gives an exhaustive list of what could have gone wrong in your installation.
You can also call following path /core/rebuild.php like: mydrupalsite.test/core/rebuild.php