CodeIgniter Forums
Working with environments - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Working with environments (/showthread.php?tid=77939)



Working with environments - tobias-stern - 11-07-2020

Hi all

I've read https://codeigniter.com/user_guide/installation/running.html and https://codeigniter.com/user_guide/general/environments.html but I still need help wrapping my head around how to work with environments. Sorry, but I'm fairly new to php and codeigniter.

So my setup is CI4 with a local development server (localhost/mysite) and a remote production server (mysite.com). I push my local changes to github where the files are copied & pasted to the webserver automatically. 

How should I setup the environments? Do I need multiple .env files, one for local and one for production? Should I .gitignore the .env and keep two seperate configurations local and on the production server? Do I have to configure something on the production webserver?

And furthermore, does it matter what baseURL is defined in App.php if I overwrite it in the .env-file anyway?

Any help is much apreaciated Smile

Regards
Tobi


RE: Working with environments - tobias-stern - 11-08-2020

I just found this part of the documentation https://codeigniter.com/user_guide/general/configuration.html where it's advised to .gitignore the .enf file. This is the advice I was looking for.

So I'll configure my setup as follows:

  • In App.php set baseURL to the production url (mysite.com)
  • leave the default .env file on the production server without any configuration, CI assumes produciton environment anyway
  • gitignore my local .env file
  • change the baseURL in my local .env to (localhost/mysite) + any other configuration
Makes it kind of hard to share local configurations with teammates but I guess it's better than before Big Grin

Any comments?
Tobias