To dynamically set ENVIRONMENT based on the server’s IP address, below I used a regular expression to check the local IP address, such as 127.0. * and 10.0. *.
At the root of your project, look at index.php and replace:
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
with:
$server_ip = getHostByName(getHostName()); if (preg_match("/^(127\.0\.|10\.0\.).+/i", $server_ip)) { define("ENVIRONMENT", "development"); define("BASEURL", "http://localhost:8000/"); } else { define("ENVIRONMENT", "production"); define("BASEURL", "https://domain.com/"); }
Be sure to replace the BASEURL value with your own and add in application/config/config.php :
$config['base_url'] = BASEURL;
To improve further addition to application/config/database.php right before the database settings $db['default'] = array( :
if(ENVIRONMENT !== 'production') { $db = [ 'username' => '', 'password' => '', 'database' => '', 'hostname' => '127.0.0.1' ]; } else { $db = [ 'username' => '', 'password' => '', 'database' => '', 'hostname' => '' ]; }
source share