Skip to end of metadata
Go to start of metadata

When developing live service but requiring continuous maintenance/development in agile manner, codes needs to be handled by the operation environment (staging/production) - you may able to add development environment by your situation. In that case include_path is super useful.

The methodology I use is including environment file based in PHP like below:

/* Copyright by Chun Kang (
* @file __env.php
* @brief environments for staging and production \n
* @author Chun Kang (
* @notes
* 2018.11.13 created

if (! defined('__CK_ENV__')) {
// Basic DB Library ------------------------------------------------------------------------------------------------------


	if (preg_match( "/staging/", getcwd())) // checking if the environment is staging or not by the current working directory
		// define include path to load necessary from staging environment
		set_include_path( ".:/web/staging_server");
		set_include_path( ".:/web/production_server");

		error_reporting(0); // turn off all error reporting

// End of Basic DB Library ------------------------------------------------------------------------------------------------------


Note set_include_path() will help you to include necessary modules by relative path easily, so you don't need to worry about remembering staging / production directory path.

If you want to hide __env.php somewhere in the system, you can simply add that condition to php.ini as following:

include_path = ".:/lib/php/environment"

If your environment is Windows, it should be like below:

include_path = ".;/lib/php/environment"

Once above is done, you can include __init.php without its detailed path anywhere in your system like below

require_once "__init.php";