Business, Tech, Life, and Whatever else

CodeIgniter Custom Settings File

by Eric Barnes on July 9, 2009

For today I am going to show you how to create a settings.php file to store your database connection and general config settings. The reason I use this method is because I am creating applications for general public usage and not all want or care about the framework driving the site. They just need a simple way to add their details and then have the script running. For this reason I create the settings.php in the site root which does two things. 1. Keeps them from having to edit files a few folders deep. 2. Simplifies the release package by not overwriting their files during upgrades.

My basic setup is like this. First create the settings.php file. Second I open up the config/database.php and copy the values into my settings file. Third I open config/config.php and find any items that I think a user would want to change or should change. I never include things in the settings file that is dependent on my setup such as prefix, query strings, etc.

Once everything is in my settings file I alter the config/database.php and delete all the $db array values. Then I add:

$active_group = "default";
$active_record = TRUE;
include(APPPATH .'/settings.php');

Then for the config/config.php file I do basically the same thing. Delete everything I included in the settings.php file and then at the top add:

include(APPPATH .'/settings.php');

Because the database and config files use a different array it doesn’t clash by including this file in both places.

Be sure and read my other CodeIgniter tips!

Subscribe Now

If you enjoyed this post, you will definitely enjoy my others. Subscribe to the feed to get instantly updated for those awesome posts soon to come.


  • You bet! I also do the same for the database but use the same type setup so didn't figure it was worth mentioning.
  • Thanks for the tip! I've recently dived into CodeIgniter hardcore and was looking for an easy solution to run a config outside of the application directory.
blog comments powered by Disqus