Keeping Dev and Prod separate

One of the tricks is keeping your development and production configuration separate. Usually the development and production environment file locations are different, the connection to you payment server will be different, database server connections will be different, so how do you keep the from updating the production environment with your development settings?

Using the file system

Most of the work I do is in PHP, so using include files works pretty good for a lot of settings. The problem is if you create a config.php file, you want to keep the development version from over writting your production version when you upload the site. What I do with my development envirornment is create a folder outside of the site to do the includes from.

Sample tree setup

mySite/include
mySite/public_html/include

I then set my include paths in the .htaccess file.

php_value include_path ".:/var/www/dev/mySite/include:
                          /var/www/dev/mySite/public_html/include"

Now place the development config.php file in mySite/include and place your production config.php file in mySite/public_html/include. Now in your PHP file, include your config file

include "config.php"

When PHP does the include on your development machine, it will include mySite/include/config.php instead of mySite/public_html/include/config.php

You can now place your development database connection information in mySite/include/config.php and the production database connnection information in mySite/public_htmlinclude/config.php and now when you upload public_html to production you do not have to worry about uploading the development configuration files.

Using a database


Create a table:

  1. CREATE TABLE `control` (
  2. `controlId` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  3. `keyName` VARCHAR(45) NOT NULL,
  4. `keyValue` TEXT NOT NULL, PRIMARY KEY(`controlId`),
  5. INDEX `keyName`(`keyName`) ) ENGINE = MyISAM;

Now populate your development database with the values for your development environment and populate your production database with values for your production environment. Now in your code, you can select the data from the database.