CodeIgniter Forums
HTACCESS setEnv doesn't work for all servers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: HTACCESS setEnv doesn't work for all servers (/thread-68103.html)

Pages: 1 2


HTACCESS setEnv doesn't work for all servers - Kaosweaver - 05-25-2017

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.


RE: HTACCESS setEnv doesn't work for all servers - InsiteFX - 05-25-2017

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

putenv


RE: HTACCESS setEnv doesn't work for all servers - Kaosweaver - 05-25-2017

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.


RE: HTACCESS setEnv doesn't work for all servers - kilishan - 05-25-2017

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.


RE: HTACCESS setEnv doesn't work for all servers - kilishan - 05-25-2017

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.


RE: HTACCESS setEnv doesn't work for all servers - Paradinight - 05-25-2017

(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


RE: HTACCESS setEnv doesn't work for all servers - kilishan - 05-25-2017

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



RE: HTACCESS setEnv doesn't work for all servers - Martin7483 - 05-26-2017

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

We have no problem setting variables using SetEnv in .htaccess


RE: HTACCESS setEnv doesn't work for all servers - dave friend - 05-26-2017

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'); 



RE: HTACCESS setEnv doesn't work for all servers - Kaosweaver - 05-29-2017

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.