7

I had a civicrm 4.4.6 site in my drupal 7 subdomain, which is beta.mydomain.com.
I want to have a backup site to perform update on civicrm, but it shows:

Fatal error: Cannot redeclare class CRM_Core_ClassLoader in /home/mydomain/www/backup/sites/all/modules/civicrm/CRM/Core/ClassLoader.php on line 36

Below is my setting scenario:

I created a subdomain, backup.mydomain.com, and copied all the files from beta site to backup site.

In beta site, these are the database: civicrm (drupal default database) and civicrmdb (civicrm database)

I had copied the database, as backup_civicrm and backup_civicrmdb

In backup site, I made the following changes:

  1. sites/default/settings.php : change database name to backup_civicrm

  2. sites/default/civicrm.settings.php :

    • define( 'CIVICRM_UF_DSN' ) : change to backup_civicrm
    • define( 'CIVICRM_DSN' ) : change to backup_civicrm
    • $civicrm_root = '/home/mydomain/www/backup/sites/all/modules/civicrm';
    • define( 'CIVICRM_TEMPLATE_COMPILEDIR', '/home/mydomain/www/backup/sites/default/files/civicrm/templates_c/' );
    • define( 'CIVICRM_UF_BASEURL' , 'http://backup.mydomain.com/' );
    • define( 'CIVICRM_MAIL_LOG', '/home/mydomain/www/backup/sites/default/files/civicrm/templates_c/mail.log' );

After configuration, my backup site shows error:

Fatal error: Cannot redeclare class CRM_Core_ClassLoader in /home/mydomain/www/backup/sites/all/modules/civicrm/CRM/Core/ClassLoader.php on line 36

I had cleared all the files in sites/default/files/civicrm/templates_c , and it does not work.

I found that when I change $civicrm_root to beta, it works.

$civicrm_root = '/home/mydomain/www/beta/sites/all/modules/civicrm';

This is weird. I need to perform upgrade on civicrm, if the root is link to beta, I'm not sure how this will affect my update.

Am I missing out any configuration? Any idea on what is the problem?

1
  • I got this error because I accidentally had 2 test sites using the same CiviCRM database. Make sure it's unique per test environment.
    – Christia
    Aug 16, 2018 at 18:17

5 Answers 5

13

It sounds as though there is either a cached path to ClassLoader.php somewhere or there are two copies of the CiviCRM code under your modules directories. Various scenarios and solutions are discussed in this forum post: svn installation says "Cannot redeclare class CRM_Core_ClassLoader" Please post back here rather than on the forum, though.

If you're sure that there aren't multiple copies of CiviCRM under /home/mydomain/www/backup/ then the most likely fix is to clear the Drupal variable civicrm_class_loader, e.g. using drush:

drush vset civicrm_class_loader ''

There's a good chance the fatal error will prevent the use of drush. In that case, you can delete the row from Drupal's variable table where name = 'civicrm_class_loader'. It's possible the variables are cached in addition -- you may need to clear Drupal's cache tables manually. (A targeted approach -- in Drupal 6, anyway -- is to delete the row from Drupal's cache table where cid = 'variables'.)

7
  • I found that it calls 2 files: /beta/sites/all/modules/civicrm/CRM/Core/ClassLoader.php and /backup/sites/all/modules/civicrm/CRM/Core/ClassLoader.php. But I don't know how to remove the calling to beta ClassLoader.php
    – vences
    Jul 21, 2015 at 9:54
  • As those two files are in different Drupal trees, this suggests that there's a cached path. Does clearing the civicrm_class_loader variable solve the problem?
    – davejenx
    Jul 21, 2015 at 9:59
  • I deleted the civicrm_class_loader row in drupal 'variable' table but it doesn't helps
    – vences
    Jul 21, 2015 at 10:03
  • Are you using a PHP opcode cache, e.g. APC or Opcache? If so, try restarting PHP. Also try clearing Civi caches again. Did you mean "define( 'CIVICRM_DSN' ) : change to backup_civicrmdb" (you wrote "backup_civicrm".) Are there any other references to the beta dbs or paths in backup's settings.php or civicrm.settings.php ?
    – davejenx
    Jul 21, 2015 at 10:24
  • Also if you haven't done so already, go to Administer -> System Settings -> Cleanup Caches and Update Paths. Correct the base directory there if necessary. Clear caches again for good measure. Verify that paths are correct at Administer -> System Settings -> Directories.
    – davejenx
    Jul 21, 2015 at 11:23
4

You can also get this error if you do something (ahem) really confused like have two copies of your Drupal site on the same machine that both point to the same CiviCRM codebase/database.

Of course you'd have to be stupid to do that. *blush*

I had the hard-coded strings in my civicrm.settings.php file pointing to paths in the other Drupal codebase. Just recording here in case it helps anyone else.

3

Try this (Drupal) :

1) Comment following lines in civicrm.settings.php :

require_once 'CRM/Core/ClassLoader.php';
CRM_Core_ClassLoader::singleton()->register();

2) Take backup of variable table in database & delete the row with name = 'civicrm_class_loader'.

3) With this your civicrm page should get loaded.

4) Now clear civicrm caches or hit "http://your_site/civicrm/menu/rebuild?reset=1" url.

5) Uncomment the above lines.

2

This can also be done w/o Drush where you examine the Drupal 'variable' table in MySQL and delete the rows that contain CiviCRM 'class loader' data.

2

If you're getting a Fatal Error: Cannot redeclare class CRM_Core_ClassLoader in /sites/all/modules/civicrm/CRM/Core/ClassLoader.php, line 36

Then a

sudo -u apache drush status

will also result in a Fatal Error - and you will also not be able to run:

drush vset civicrm_class_loader ''

You're definitively looking for multicode bases: perhaps you're getting this after an upgrade and you copied your old CiviCRM code to civicrm-old or something like that.

rm -r civicrm-old/ 

will fix this.

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.