HTACCESS setEnv doesn't work for all servers |
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.
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.
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.
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.
(05-25-2017, 11:01 AM)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
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
My company uses servers with centOS + Plesk running Apache. PHP is running as FastCGI
We have no problem setting variables using SetEnv in .htaccess
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');
Sorry all, the notifications stopped coming or I would have responded...
The server is running Apache and centOS (with a CPanel and all) it does read the htaccess and dies when the SetENv line is enabled. The log message was pretty clear - SetEnv isn't supported: [Thu May 25 15:46:00.548750 2017] [core:alert] ******mypath******/public/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration I'll pull the latest and try that out and let you know. And I'll also check the mod_env to see if that set to work. Sorry I'd not known about the responses and I appreciate the help. |
Welcome Guest, Not a member yet? Register Sign In |