Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting environment variable using .htaccess

I'm trying to set up an apache environment variable using .htaccess file in the following way:

SetEnv SERVER_KEY "qwerty"

After that i gracefully restart my apache web server:

apachectl graceful

Then i create a file called version.php in /var/www/html

<?php phpinfo() ?>

And go to MYIPADDRESS/version.php to check but i find out that the environment variable has not been set up.

Here are further details: OS: RHEL6 PHP Version: 5.3.3 Apache Version: 2.2.15 (Red Hat)

What do i do?

Update: I solved my problem by changing AllowOverride None to AllowOverride All in the server configuration file!

like image 810
nmadhok Avatar asked Jul 10 '13 21:07

nmadhok


1 Answers

  1. Check that the htaccess is being read at all, make sure you've configured your host so that it allows (at the very least) "FILEINFO", or better yet, set it to "ALL"

    AllowOverride ALL
    
  2. If not, make sure your mod_env module is being loaded in your server config.

  3. Make sure you're looking in the right place. Apache internal environment variables are passed along to php via the $_SERVER[] array (on the phpinfo() page, under Apache Environment) and they are different from php runtime environment variables.(which are under Environment),

like image 76
Jon Lin Avatar answered Sep 21 '22 13:09

Jon Lin