Published by Mijingo

movie icon image

ExpressionEngine How-to Articles

Topics range from beginner to advanced, but are all born out of real world, professional, day-to-day use of ExpressionEngine. Need more information? Get training videos and ebooks on ExpressionEngine from Mijingo.

Creating a Robust Config.php File

A frequent question in the forums is how to easily move a site from a staging or local server to a production server without everything breaking. While site migration is out of the scope of this article, I do want to address one simple way you can make moving sites easier: create a robust config.php file.

In recent versions of ExpressionEngine, the config.php file has become leaner as more of the installation settings have been moved into the database. This can be a inconvenience when moving a site to a different server because it requires making so many database changes and isn’t as portable as file.

Luckily, we can still use the config.php file to override settings in the database.

This is what a typical EE config file looks like after a fresh install:


	if ( ! defined('EXT')){
	exit('Invalid file request');

	$conf['app_version'] = "167";
	$conf['license_number'] = "";
	$conf['debug'] = "1";
	$conf['install_lock'] = "1";
	$conf['db_hostname'] = "localhost";
	$conf['db_username'] = "username";
	$conf['db_password'] = "password";
	$conf['db_name'] = "sample";
	$conf['db_type'] = "mysql";
	$conf['db_prefix'] = "exp";
	$conf['db_conntype'] = "0";
	$conf['system_folder'] = "system";
	$conf['cp_url'] = "http://sample:8888/system/index.php";
	$conf['doc_url'] = "";
	$conf['cookie_prefix'] = "";
	$conf['is_system_on'] = "y";
	$conf['allow_extensions'] = "n";
	$conf['multiple_sites_enabled'] = "n";

There are a few standard lines that I always add to every project I’m working on.

Site URL

This is the base URL of your website and impacts how EE generates URLs, so it’s important to make sure it’s correctly set when moving servers.

$conf['site_url'] = "http://sample:8888/";
Template Path

When you move an EE-powered site to a new server and have saved templates as files, one of the first things you have to change is the server path to the templates. Without doing this you might end up with the incorrect templates showing (the ones last saved to the database) or blank pages. To make this easier to adjust, let’s add a config line for the template path.

$conf['tmpl_file_basepath'] = "/path/to/system/templates";
Control Panel Theme

We’ve all done it. You move a site to a new server and you log in to the control panel and are greeted with an unstyled mess that looks nothing like it should. This is usually because the Theme Folder URL and Server Path are set incorrectly. This is normally stored in the database, but we can make it easier to edit by pulling the config back into the config.php file. Let’s add two new lines: one for the Theme Folder URL and one for the Theme Folder Server Path.

$conf['theme_folder_url'] = "http://sample:8888/themes/";
$conf['theme_folder_path'] = "/path/to/themes/";
CAPTCHAs and Avatars

But wait, there’s more! You can also specify the path and URL for CAPTCHAs and avatars. Again, these settings are normally stored in the database, but let’s pull them out for easier editing.

First, CAPTCHAs:

$conf['captcha_path'] = "/path/to/images/captchas";
$conf['captcha_url'] = "http://sample:8888/images/captchas";

And now avatars:

$conf['avatar_path'] = "/path/to/images/members/avatars";
$conf['avatar_url'] = "http://sample:8888/images/members/avatars";
A Little Further

Now that you’ve abstracted out some important settings, you can set up multiple config.php files for each environment you work in. E.g. developing locally, staging and production.

I usually create files with names like these: config.php.production, config.php.staging and and then rename the appropriate file to just config.php.

There are also other ways to go about this. Explore the following resources for more information:

Posted on Feb 04, 2009

Filed Under: How-To, ExpressionEngine Development,

Ryan Irelan
About Ryan Irelan

Ryan Irelan is the Technology and Development Director at Happy Cog, a web design and development firm. He is a noted ExpressionEngine expert, having created a wildly popular video training series on ExpressionEngine. Additionally, Ryan is the publisher of EE Insider, a well-known news and information site for the ExpressionEngine community. In his spare time, Ryan is the production director of A List Apart Magazine, which is one of the most popular ExpressionEngine-powered sites on the web. Recently, Ryan published a book on ExpressionEngine 2 called "ExpressionEngine 2: A Quick-Start Guide."