1

This is starting to make me tear my hair out. I've worked with NSM config bootstrap (http://ee-garage.com/nsm-config-bootstrap) on several sites now. It enables you to set your database connection details in the bootstrap file, which should override database.php, and they change depending on which server environment you're looking at. The issue I'm having is that changing my connection settings in the bootstrap file isn't overwriting the settings in database.php, so I'm getting connection errors on either the local or the stage, depending on what I put in database.php. My file structure is:

system
    expressionengine
        config
            config.php
            database.php
            config_bootstrap.php

At the bottom of config.php and database.php I have this line:

require_once(realpath(dirname(__FILE__) . '/config_bootstrap.php'));

The relevant part of my bootstrap file looks like this:

// Define the environment settings

$env_config = array();
$env_db_config = array();
$env_global_vars = array();

// Set the environmental config and global vars
if (NSM_ENV == 'local') {
    $env_db_config = array(
        'hostname' => 'localhost',
        'database' => 'database',
        'username' => 'username',
        'password' => 'password',
    );
    $env_global_vars = array(
        'global:cm_subscriber_list_slug' => ''
    );
}
elseif(NSM_ENV == 'staging') {
    $env_db_config = array(
        'hostname' => 'localhost',
        'database' => 'database',
        'username' => 'username',
        'password' => 'password',
    );

    $env_global_vars = array(
        'global:cm_subscriber_list_slug' => ''
    );

    $env_config = array(
        'webmaster_email' => 'webmaster@' . NSM_SERVER_NAME,
        'webmaster_name' => 'Webmaster',
    );
}
else {
    $env_db_config = array(
        'hostname' => '',
        'database' => '',
        'username' => '',
        'password' => '',
    );
    $env_global_vars = array(
        'global:cm_subscriber_list_slug' => '',
        'global:google_analytics_key' => 'XX-XXXX'
    );
}

I know the bootstrap file is being included, as it's also setting things like my template directory and file upload paths etc correctly, it appears that it's just the database settings that it's not overriding. I thought it may be permissions, but database and config files are 666, so it should be ok.

Please let me know what other information I need to include if this isn't enough.

  • Have you checked that your NSM_ENV constant is being defined properly? – Tyssen Feb 23 '13 at 12:38
  • Yes, there's a debug build into it which lets me echo out the environment and that's working on both local and stage – darylknight Feb 23 '13 at 12:44
0

Ok, problem solved. I don't understand WHY this fixes it though so if anyone could comment on that, much appreciated.

My config.php and database.php files have this at the bottom of them:

require_once(realpath(dirname(__FILE__) . '/config_bootstrap.php'));

Change it to:

require(realpath(dirname(__FILE__) . '/config_bootstrap.php'));

And it all works as it should. It doesn't seem to matter if config.php is require or require_once, but database.php has to be require.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.