Blog/ How To Perform A Registry Rebuild Manually In Drupal?

By rakesh.james Thu, 03/26/2015 - 18:21 Comments

There are several cases where you will have to rebuild the registry in Drupal. I have encountered one such case in the form of this error:

Fatal error: require_once(): Failed opening required '/files/mailsystem/HTMLMailSystem__SmtpMailSystem.mail.inc'  

This error seems to be occurring in many scenarios.

Ideally, a Registry Rebuild would take care of the issue. But it didn’t help in my case.

I even tried to run a drush rr command but it didn’t work.

I began to look for other solutions. This is when I decided to rebuild the registry manually.

The following steps are involved in rebuilding the registry manually in Drupal:

1) Install Drush.

2) Take a backup of your database. Or take backups of {registry} and {system} tables. Run the following code using Drush to back up the tables:

drush sqlq "CREATE TABLE registry_bak LIKE registry; INSERT INTO registry_bak SELECT * FROM registry;"
drush sqlq "CREATE TABLE system_bak LIKE system; INSERT INTO system_bak SELECT * FROM system;"

3) Truncate {cache_bootstrap} and {registry} tables:

drush sqlq "TRUNCATE cache_bootstrap; TRUNCATE registry"

4) Insert the Controller name, type and filename in the {registry} table:

drush sqlq 'INSERT INTO registry (name, type, filename) VALUES ("SelectQueryExtender", "class", "includes/database/select.inc"), ("DrupalDefaultEntityController", "class", "includes/entity.inc");'

5) Update the registry values:

drush eval "registry_update();"

6) Clear the Caches:

drush -y cc all

The above steps will help you rebuild the registry. If you are not using Drush, you can run these commands via SQL with your respective database.

After following the above steps, you may still get an error such as the one below:

Fatal error: Class 'Entity' not found in rules.module on line 

You will have to run the following line command to learn where the entity class is located:

$ grep -Rwl "^class Entity" 

It gives you the following result:

./sites/all/modules/entity/includes/entity.inc 

Then run the following line:

$ drush sqlq 'INSERT INTO registry (name, type, filename) VALUES ("Entity", "class", "sites/all/modules/entity/includes/entity.inc");'

And clear the caches again:

drush -y cc all

You have now successfully performed a Registry Rebuild manually in Drupal.  

Ready to get Started?