I'm trying to understand the best course of action with using multiple environments, such as development, testing, production for my application with codeigniter.
As of right now I have one folder for my application. I'm seen places that talk about in the config file doing a folder for each of the environments and placing for example a copy of the database file in each of the environment folders.
Is this the best method of handling multiple environments? The reason I'm asking is because if I work on my dev subdomain I'd still have to reupload to the main root folder all the same files. Is this the best workflow?
So basically I have two sites.
dev.siteurl.com siteurl.com
I'm trying to figure out the best option of handling this. Because I'm wondering if I'm going to just have to reupload all the files again to the main level so that it can handle the production server or is there an easier way.
CodeIgniter makes it simple and painless to set Environment Variables by using a “dotenv” file. The term comes from the file name, which starts with a dot before the text “env”. CodeIgniter expects . env to be at the root of your project alongside the app directories.
CodeIgniter has a config file that lets you store your database connection values (username, password, database name, etc.). The config file is located at app/Config/Database. php.
Yes the way it works is under your /application/config folder you create an extra nested folder called development so that you have
/application/config/development/
Inside development you will place a copy of your database.php file and change your development database settings
/application/config/development/database.php
THEN you have to tell codeigniter which version you are on, so in your base root folder edit index.php:
/index.php
define('ENVIRONMENT', 'development');
When you want to use the /config/development/database.php you will change your environment to development, and when you want to use the production database you will change the environment to production
edit: also the CI TOC has a brief section explaining this: https://www.codeigniter.com/user_guide/general/environments.html
I'm defining envirement in index.php
do something like
if ($_SERVER['SERVER_NAME']=='siteurl.com')
define('ENVIRONMENT', 'production');
else if ($_SERVER['SERVER_NAME']=='test.siteurl.com')
define('ENVIRONMENT', 'testing');
else
define('ENVIRONMENT', 'development');
and use config sections according to ENVIRONMENT variable
I know this is an old thread, but I am working on a Codeigniter project now and was looking for a good way to maintain two environments without having to maintain two codebases at two different urls. In case anyone else is looking for a similar answer, here's a possible solution that allows you to maintain one codebase.
For my current project, I have siteurl.com and siteurl.com/sandbox.
siteurl.com/index.php
define('ENVIRONMENT', 'production');
$system_path = '../system';
$application_folder = '../application';
siteurl.com/sandbox/index.php
define('ENVIRONMENT', 'development');
$system_path = '../../system';
$application_folder = '../../application';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With