2

My .htaccess:

SetEnv tvar "my value"
RewriteEngine on
RewriteRule .* - [E=boostpath:normal]

My virtual host settings:

   AllowOverride All
   Options FollowSymLinks
   Require all granted
   ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/home/dir/public_html/www.site.com/$1

My php file:

<?php
putenv("foo=bar");
echo "<br><br>env";
echo getenv("foo"); #works, outputs bar
echo "<br><br>env2";
echo getenv("tvar"); #doesn't work, empty
echo getenv("REDIRECT_tvar"); #doesn't work, empty
echo "<br><br>";
echo "<br><br>env3";
echo getenv("boostpath"); #doesn't work, empty
echo getenv("REDIRECT_boostpath"); #doesn't work, empty
echo "<br><br>";

print_r($_ENV) is also empty. But I tried turning variables_order = 'EGPCS' in php.ini and $_ENV shows up right but without any of the .htaccess set variables, and the result of the script is the exact same. Need this to work for a site to be able to cache both mobile and not mobile viewers in different directories.

  • I used RewriteRule instead of ProxyPassMatch and it broke my web applications, but the environment variables did pass and were set. Can anyone help me correctly change the ProxyPassMatch to RewriteRule? http://serverfault.com/questions/398834/understanding-apache-2-4-mod-proxy-fcgi-and-rewriterules-in-htaccess That sort of worked (it worked for the test) but it completely broke drupal. –  Oct 02 '14 at 18:35

1 Answers1

0

In your VirtualHost directive:

<Directory /home/dir/public_html/www.site.com>
    AllowOverride All
    Options FollowSymLinks
    Require all granted
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} ^/((.*\.php)(/.*)?)$
    RewriteCond %2 -f
    RewriteRule . fcgi://127.0.0.1:9001/%1 [L,P]
    RewriteOptions Inherit
</Directory>

Site is fast, drupal works, other files work, environment variables passed. DO NOT USE ProxyPass OR ProxyPassMatch!!!! It will not pass environment variables and break some php packages. Some have shown you can use LocationMatch and Interpolation but this seems to only work for ajp:// and not fcgi:// !!!

Unfortunately, this sets the user not to what is set in the php-fpm pool configuration but to the apache user and group. That is another question though so I will mark this resolved. I have to change writable folders to the apache user and group, which is sort of secure if you think about it, but it is also non sequitur and has some weird issues.