WordPress wp-config.php from Local to Staging to Live

wp-config local to staging to live One of my favourite talks from WordCamp Bournemouth was Mark Wilkinson’s ‘From Local to Staging to Live Using Version Control and Deployment Tools’. I always find it fascinating to see how different developers work and the tools they use to do their business. One hurdle in using GIT and WordPress Mark found was the good ‘ole wp-config.php file. Yes, that one. That file we all love editing. The file that probably causes more problems and more elation than any other, particularly for those who are just getting to grips with WordPress. Like it or not, if you are installing WordPress for the very first or umpteenth time you may need to edit your wp-config.php file. It’s time to grasp that nettle…

From local to staging to live

If you are working across 3 ‘environments’, let’s say, your local development machine, a staging server and your ‘live’ production server, you could find yourself with three wp-config files! Throw GIT version control into the mix, and things can start getting a little messy. There are many ways around this. I am not saying this is how it should be done, but rather this is how I do it. By all means, if you have a more splendid way of achieving this goal, then please share it!

Bring out the Snake Oil

My wp-config file uses a simple php switch to determine if WordPress is running on a local machine or on staging or production servers.

So, all I do is enter my environments. e.g:
‘development’ => ‘mysite.dev’,
‘staging’ => ‘mysite.staging.wpengine.com’,
‘production’ => ‘mysite.com’,

I use MAMP Pro for my local development and it is a breeze adding a new host such as ‘family.dev’ or ‘mysite.dev’. Then I enter my staging and production URLS. Typically I use WPEngine for my staging and live servers. But the principle is the same for all hosts. So, when WordPress is run this switch looks for the php SERVER_NAME and depending where it is running, be it on my iMac or staging or production servers it defines the correct database connection as well as some other optional variables and constants. For example you might want WP_DEBUG to be set to TRUE on your local machine but set to false on your live server. You don’t want the whole world to see any debugging messages. Similarly, WP_CACHE might be set to false on your local machine but you probably want to cache your live site.

You can also set your language and also WP_SITEURL and WP_HOME constants depending on wether you are local, staging or live. Which I find particularly useful.

Also setting WP_LANG in the wp-config.php file is something I do all the time. e.g: ‘en_GB’.

Before you begin:

  1. If you have a working wp-config.php file, make a copy before you edit it! You can thank me later.
  2. Use strong passwords! One other highlight of WordCamp Bournemouth was Mike Little’s lightning talk on passwords. In short, make your passwords 12 characters long or longer. Yes, size does matter!

‘One size fits all’ wp-config.php: