Welcome Guest, Not a member yet? Register   Sign In
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 CodeIgniter Community 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.
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.
Reply
#6

(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
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
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
#10

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB