SetEnv in htaccess file doesn’t work with PHP-FPM

apache-2.4codeignitermpm-eventphp-fpm

I'm moving from a prefork apache setup to event mode with php-fpm. In prefork mode, I can use SetEnv directives in an htaccess file like so:

SetEnv CI_ENV testing

And that value ends up in PHP:

echo $_SERVER["CI_ENV"]; // outputs "testing"

However, with apache in event mode, that value no longer gets into PHP. Is something broken? What is the best, most orthodox way to fix this? Should I put a SetEnv command in the VirtualHost directive? In the php-fpm.conf file? Please advise.

S

Best Answer

Everyone should be delighted to know that you can in fact put a SetEnv directive in your VirtualHost in the apache configuration file and this still works, even with PHP-FPM.

In my case, that file is /etc/apache2/sites-available/default-ssl.conf:

sudo nano /etc/apache2/sites-available/default-ssl.conf

Within the VirtualHost in there, you can add your SetEnv directive:

    <VirtualHost _default_:443>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html

            # ETC ETC ETC

            # added because it doesn't work from .htaccess file with PHP-FPM
            SetEnv CI_ENV testing

            # ETC ETC ETC
    </VirtualHost>