I have a working drupal site at www.example.com, and I'm trying to set up a test site at test.example.com (www goes to public_html, test goes to public_html/test). I'm trying to keep the codebases and databases of these two sites separate, so I set up a complete installation inside the /test directory. What I get is two sites with different codebases but the same database (the settings.php file in /test/sites/default has different settings than the one in /sites/default.

I thought maybe I could get around this by setting up a settings.php file for the test site at /sites/test.example.com/settings.php but that didn't work either.

I'm sure I must be missing something obvious, but I've been searching through the forums and can't quite figure out what I'm doing wrong. Any tips appreciated, and let me know if I'm leaving out any crucial information.

Comments

rays’s picture

Sounds like you need to create a new test database then point settings.php to that new database. For example: Create a new database called test... follow the same procedure as you did during the install. Open settings.php in your /test/sites/default directory the change the database name to test.

$db_url = 'mysql://user:password@localhost/test';

Ray

njehlen’s picture

Sorry - I should have included more detail.

I have two different databases (for clarity, I'll call them mainsite and testsite). testsite was created as a copy of mainsite, and then I pointed /sites/default/settings.php $db_url to the mainsite database and /test/sites/default/settings.php $dburl to testsite, but when i visit test.example.com the database its using is the mainsite one. I figured this out by changing the styles on the installation in the /test directory so that the background is a different color, which worked, but then when I add a block to the test site it shows up in both the main site and the test site.

Any other ideas what I might be doing wrong?

rays’s picture

A few ideas...

1) Not sure what utility you used to create your database copy from mainsite to testsite... Is it possible that the utility is trying to keep the two database images in sync?
2) rename your $dburl that points to the testsite database to junksite then try and run the test Drupal site to see if an error occurs or if you hit the mainsite database. This will determine if Drucal can see the testsite $db_url.
3) Does the same thing happen if you run your test site from example.com/test rather that test.example.com?

lastly, please post a copy of both your $db_url stamements.

Ray

njehlen’s picture

Thanks for your help with this.

1) I exported the database using phpmyadmin and then reimported into the test database, so I don't think its a sync problem.
2) I tried renaming the $dburl that points to the test database, but it had no effect.
3) I actually can't reach the test site at example.com/test for some reason - it gives me a Drupal "page not found" error.

Here are my db_url statements (cleaned up for safety)

test/sites/default: $db_url = 'mysql://username:password@localhost/site_drupaltest';
sites/default: $db_url = 'mysql://username:password@localhost/site_drupal';

rays’s picture

2) I tried renaming the $dburl that points to the test database, but it had no effect.

This should have caused an error... so, Drupal is not seeing the settings.php file of your testsite.

3) I actually can't reach the test site at example.com/test for some reason - it gives me a Drupal "page not found" error.

this may be the root of the problem... no pun intended. Try this:

In both settings.php files specify the base_url for your sites: (testsite shown below)

$base_url = 'http://example.com/test';

Also may want to check your subdomian pointers to ensure thay are correct.

Hope this helps,
Ray

njehlen’s picture

Ray - thanks for all your help narrowing down this problem. I finally decided to try and trace how Drupal was getting the location of the settings file and openned up my bootstrap.inc file. For some reason in the conf_init function, the "require_once" was set manually instead of using the conf_path function.

I can't figure out why this would have happened - I installed Drupal myself and I've never touched the bootstrap.inc file. Is this something that someone at my host would have done for some reason?

Anyway, I doubt this is something that other people will run into, but just in case, open up bootstrap.inc and look for this code (this is from a fresh download of Drupal 4.7.3):

function conf_init() {
  global $db_url, $db_prefix, $base_url, $base_path, $base_root, $conf;
  $conf = array();
  require_once './'. conf_path() .'/settings.php';

In my case, that require_once code was changed.

Once I changed it to the actual location of the test settings file, it started using the proper database.

benthere’s picture

Try renaming the .htaccess to something else on the main site temporarily.

If that allows you to access example.com/test or test.example.com correctly, then you'll need to make some modifications to that .htaccess to stop it from interfering with the other site.

Let me know if that helps anything and I'll help you work out a RewriteRule.

--
Cheap, reliable Drupal hosting: 20GB | 1TB
Save $75| DH75OFF coupon for 1 year ($3.75/mo!)
Save $50| DH02SETUP coupon for monthly ($10/mo!)