0

I am running PHP apps on a webserver with apache2 (v2.4.25) and php7.1-fpm.

I need to share env var for both php7.1-fpm and php CLI script.

I edit /etc/php/7.1/fpm/pool.d/www.conf as folow:

env['MYVAR']= thisismyvar

The access by the web apps is OK using the getenv('MYVAR')

But I need this env var to be set for my CLI script too.

This test command does not return anything: sudo -u www-data env | grep MYVAR

My question is: how can I share env var for php-fpm (with apache2) and php CLI scripts without copying/pasting?

My apache2 vhost:

<VirtualHost *:80>
    ServerName app.company
    DocumentRoot  /var/www/app1/app/public/

    <Directory /var/www/poll>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch \.php$>
        # Apache 2.4.10+ can proxy to unix socket
        SetHandler "proxy:unix:/var/run/php/php7.1-fpm.sock|fcgi://localhost/"
    </FilesMatch>
    ErrorLog ${APACHE_LOG_DIR}/app1-error.log
    CustomLog ${APACHE_LOG_DIR}/app1-access.log combined    
</VirtualHost>
ben.IT
  • 1,490
  • 2
  • 18
  • 37
  • Does this answer your question? [How to get system environment variables into PHP while running CLI & Apache2Handler?](https://stackoverflow.com/questions/13568191/how-to-get-system-environment-variables-into-php-while-running-cli-apache2hand) – Rain Jan 06 '20 at 13:08
  • thanks for your answser, but this seems to only work with Apache2Handler and NOT with php-fpm. I actually don't know how to proceed without both editing `/etc/environment` and `/etc/php/7.1/fpm/pool.d/www.conf`. In this way, the value of env var can be different and this is what I want to prevent. – ben.IT Jan 06 '20 at 15:46

0 Answers0