• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTACCESS setEnv doesn't work for all servers

#1
The setEnv CI_ENV development line in the htaccess does not work for centOS servers and it comes as the default (and only) line for setting the environment.

I've searched for ways to replicate this command for non-csh compatible commands and have come up empty (every single one of them throws a 500 server error, manually setting the variable via define throws a CI error)

If CI4 intends to use the .htaccess to set variables, it needs to either be globally correct in how it is done (or more likely) setup different htaccess files for platforms.

If anyone knows how to make a compatible command for centOS in the htaccess, I'd love to know.
Reply

#2
You can try this, not tested but may work for you.

putenv
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#3
For now I've just set the $_SERVER['CI_ENV'] to control the environment (in the index.php in the public folder). That works for now, but I'm still searching for how to do it in the htaccess.

Thanks for the reply.
Reply

#4
Kaosweaver - fair point. I didn't realize centOS wouldn't support that.

My initial reaction was that it is the same way that it was done in CI3, but I just glanced back and remembered it was moved into the CodeIgniter app. It looks like the best solution here would be to move the environment check back to the index file.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#5
Just a thought - is your centOS setup running Apache or a compatible server that actually reads the .htaccess file? If it's, for example, nginx, you would have to do it completely differently.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#6
(05-25-2017, 12:01 PM)kilishan Wrote: Just a thought - is your centOS setup running Apache or a compatible server that actually reads the .htaccess file? If it's, for example, nginx, you would have to do it completely differently.

500 is a good error. He/She should check the error log.


https://httpd.apache.org/docs/2.4/mod/mod_env.html

Try on the server a2enmod env
Reply

#7
I just modified the framework to allow the value to be set in a .env file. I also changed the name to CI_ENVIRONMENT for more clarity.

Please pull down the latest changes on the develop branch, set the following line in your .env file and let me know if it works for you:

Code:
CI_ENVIRONMENT = develop
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#8
My company uses servers with centOS + Plesk running Apache. PHP is running as FastCGI

We have no problem setting variables using SetEnv in .htaccess
Reply

#9
If the server is running Apache then mod_env must be enabled for setEnv to work. I have run into cases where mod_env is not enabled in shared hosting setups.

The fix that has worked for me is to change the define in index.php to this.

PHP Code:
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production'); 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.