Jump to content

Multiple Environment Configuration


David Beesley
 Share

Recommended Posts

Hi All,

I am in the process of creating a base processwire setup for our company.
This will include boilerplate templates, a sass/css framework and some common config settings. I have remove the bundled site profiles and will build ours out using the default one as a jumping off point.

As part of this, I am trying to add a switch statement to the config.php files to store database details for all three environments the site can exist in (Dev, Stage, Production).

switch (strpos($_SERVER['HTTP_HOST'])) {

    // Local Development Environment (MAMP)
    case 'name.project' :
        $config->dbHost = 'localhost';
        $config->dbName = '';
        $config->dbUser = '';
        $config->dbPass = '';
        $config->dbPort = '3306';
        break;


    // Testing/Staging Environment
    case 'testdomain.co.uk' : 
        $config->dbHost = 'localhost';
        $config->dbName = '';
        $config->dbUser = '';
        $config->dbPass = '';
        $config->dbPort = '3306';
        break;


    // Live/Production Environment (domain.tld)
    case 'domain.tld' : 
        $config->dbHost = 'localhost';
        $config->dbName = '';
        $config->dbUser = '';
        $config->dbPass = '';
        $config->dbPort = '3306';
        break;
}

The installation process I originally envisaged was the once one of us had pulled down the base project, copied it to the project repo, pointed MAMP at it and setup a local database, they entered the dev database details and hostname in that case in the switch statement and ran the installer. I was hoping the installer would simply skip the part where you added the database details and populate the database and carry on. Instead, it throws an error that certain tables are missing but the installer was still present.

My next approach was to leave the two other environments in the switch statement, run the installer and enter the database details like normal and hope it put the dev details straight after the comment

/*** INSTALLER CONFIG ********************************************************************/

This would become the default, and then be overridden if the switch statement caught a case. However it inserts the entered details at the end of the file.

Is there any way I can achieve one of the two goals above, or could anyone suggest an alternative approach?

 

Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...