2

My question is similar to Subdomain database configuration picking up root domain config, but I don't have any custom database variables.

I have a staging site and a (forthcoming) production site on the same remote shared hosting server. The staging site is at a staging subdomain and the production site will be at the root.

The staging site seems to be using the config variables from the root domain in general.php and db.php. I had to take the production site out of db.php to get the staging site to work at all, and anywhere I'm using environment variables (like my asset paths), they're coming from the production config instead.

This is my general.php:

return array(
  '*' => array(
    'omitScriptNameInUrls' => true,
    'generateTransformsBeforePageLoad' => true,
    'loginPath' => 'admin',
  ),
  'localhost' => array(
    'server' => 'localhost',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'C:\wamp\www\craftcms',
      'baseUrl'  => 'localhost/craftcms/',
    )
  ),
  'staging.safs.msu.edu' => array(
        'server' => '35.8.12.67',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'staging',
      'baseUrl'  => 'http://staging.safs.msu.edu',
    ),
  ),
  'safs.msu.edu' => array(
    'server' => '35.8.12.67',
    'devMode' => false,
    'environmentVariables' => array(
      'basePath' => '',
      'baseUrl'  => 'http://safs.msu.edu',
    ),
  ),
);

How do I get my config files to recognize the staging subdomain's settings?

2 Answers 2

2

Craft looks for partial matches to apply config settings (both general.php and db.php which means you can do things like:

'.dev' => array(
.. 

'.com' => array(
..

Craft applies these settings for each match from the top of the file to the bottom. So in your case because you have the the production domain after your subdomain config it matches and overrides your subdomain settings.

Simply swap your config variables over and it'll work.

return array(
  '*' => array(
    'omitScriptNameInUrls' => true,
    'generateTransformsBeforePageLoad' => true,
    'loginPath' => 'admin',
  ),
  'localhost' => array(
    'server' => 'localhost',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'C:\wamp\www\craftcms',
      'baseUrl'  => 'localhost/craftcms/',
    )
  ),
  'safs.msu.edu' => array(
    'server' => '35.8.12.67',
    'devMode' => false,
    'environmentVariables' => array(
      'basePath' => '',
      'baseUrl'  => 'http://safs.msu.edu',
    ),
  ),
  'staging.safs.msu.edu' => array(
    'server' => '35.8.12.67',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'staging',
      'baseUrl'  => 'http://staging.safs.msu.edu',
    ),
  ),
);
3
  • Thanks for the quick response. However, when I do that, the config variables seem not to be recognized at all. DevMode is not turned on for the staging site, and my asset paths contain {baseUrl} instead of http://safs.msu.edu like they did when they were using the root domain settings. Commented Sep 14, 2016 at 15:18
  • Yeah - stupid mistake by me - updated answer with the solution :) Commented Sep 14, 2016 at 15:24
  • There we go! I should have tried switching the order - makes sense. Thanks. Commented Sep 14, 2016 at 15:26
0

I tend to put the settings for the Production site under the wildcard settings '*' and then overwrite any for dev and staging below that.

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.