When moving a live and growing EE2 install into a git repository, I quickly got tired of tweaking the config.php and database.php files when deploying to dev, stage, or prod. File upload locations, theme locations, database names, etc.
Below are the ExpressionEngine2 config.php and database.php tweaked to allow for easy multiple deployment locations.
config.php
All the absolute paths have been changed to relative and a little PHP to figure out some basic server things.
Omit the <?php... line and add the code below to the bottom of the stock config.php
<?phpif(!defined('BASEPATH'))exit('No direct script access allowed');// ...// Add the below to the bottom of the config.php file...// ...// Dynamic paths for cross-server compatibility$protocol=(isset($_SERVER["HTTPS"])&&$_SERVER["HTTPS"]=="on")?"https://":"http://";$base_url=$protocol.$_SERVER['HTTP_HOST'];$base_path=$_SERVER['DOCUMENT_ROOT'];$system_folder="system";$images_folder="images";$images_path=$base_path."/".$images_folder;$images_url=$base_url."/".$images_folder;$config['index_page']="";$config['base_url']=$base_url."/";$config['site_url']=$config['base_url'];$config['cp_url']=$config['base_url'].$system_folder."/index.php";$config['theme_folder_path']=$base_path."/themes/";$config['theme_folder_url']=$base_url."/themes/";$config['tmpl_file_basepath']=$base_path."/assets/site_themes/";#Changed from Matt's original config. This change allows for my templates to sit outside of the EE system folder$config['emoticon_path']=$images_url."/smileys/";$config['captcha_path']=$images_path."/captchas/";$config['captcha_url']=$images_url."/captchas/";$config['avatar_path']=$images_path."/avatars/";$config['avatar_url']=$images_url."/avatars/";$config['photo_path']=$images_path."/member_photos/";$config['photo_url']=$images_url."/member_photos/";$config['sig_img_path']=$images_path."/signature_attachments/";$config['sig_img_url']=$images_url."/signature_attachments/";$config['prv_msg_upload_path']=$images_path."/pm_attachments/";// Debugging and performance$config['show_profiler']='n';# y/n$config['template_debugging']='n';# y/n$config['debug']='1';# 1: Errors shown to Super Admins. 2: Errors shown to everyone.$config['disable_all_tracking']='y';# y/n$config['enable_sql_caching']='n';# Cache Dynamic Channel Queries?$config['email_debug']='n';# y/n/* End of file config.php *//* Location: ./system/expressionengine/config/config.php */
database.php
The database connection details are set based on the EE URL.
<?phpif(!defined('BASEPATH'))exit('No direct script access allowed');$active_group='expressionengine';$active_record=TRUE;// Setup the environmentif(!defined('RWBAKER_ENV')){define('RWBAKER_SERVER_NAME',$_SERVER['SERVER_NAME']);// Set the environmentif(strstr(RWBAKER_SERVER_NAME,'local.'))define('RWBAKER_ENV','local');elseif(strstr(RWBAKER_SERVER_NAME,'dev.'))define('RWBAKER_ENV','development');elseif(strstr(RWBAKER_SERVER_NAME,'stage.'))define('RWBAKER_ENV','staging');elsedefine('RWBAKER_ENV','production');}// Set the environmental config and global varsif(RWBAKER_ENV=='local'){$db['expressionengine']['hostname']="";$db['expressionengine']['username']="";$db['expressionengine']['password']="";$db['expressionengine']['database']="";}elseif(RWBAKER_ENV=='development'){$db['expressionengine']['hostname']="";$db['expressionengine']['username']="";$db['expressionengine']['password']="";$db['expressionengine']['database']="";}elseif(RWBAKER_ENV=='staging'){$db['expressionengine']['hostname']="";$db['expressionengine']['username']="";$db['expressionengine']['password']="";$db['expressionengine']['database']="";}else{$db['expressionengine']['hostname']="";$db['expressionengine']['username']="";$db['expressionengine']['password']="";$db['expressionengine']['database']="";}$db['expressionengine']['dbdriver']="mysql";$db['expressionengine']['dbprefix']="exp_";$db['expressionengine']['pconnect']=FALSE;$db['expressionengine']['swap_pre']="exp_";$db['expressionengine']['db_debug']=FALSE;$db['expressionengine']['cache_on']=TRUE;$db['expressionengine']['autoinit']=FALSE;$db['expressionengine']['char_set']="utf8";$db['expressionengine']['dbcollat']="utf8_general_ci";$db['expressionengine']['cachedir']="../cache/db_cache/";/* End of file database.php *//* Location: ./system/expressionengine/config/database.php */