Posted in Code Snippets, PHP

PHP INI parser with environment support

Reading the INI file using PHP, based on the environment can be performed using few configuration in Apache.

Step 1: Set environment in Apache

Open the apache.conf or httpd.conf from apache server’s directory and add the following line:


Step 2: Create INI files

Create files using format <filename>.<environment>.ini

Say, or

Example INI file –

js =
css =

Step 3: Use the config class

Step 4: Example


require_once "class.config.php";

var_dump(Config::getEnvironment());           // dev
var_dump(Config::isEnvironment('dev'));       // TRUE

Now, it can be seen that this reads file. Similarly, when apache server’s SetEnv is set to prod, will be read.

In this way, INI can be parsed based on different environment. Free from configuration issues across environments.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s