Environment variables and PHP

前端 未结 4 998
抹茶落季
抹茶落季 2020-12-09 04:34

I have an ubuntu server with a handful of custom environment variables set in /etc/environment as per the ubuntu community recommendation

When I use php from the com

4条回答
  •  不知归路
    2020-12-09 04:48

    Adding on to the answers above, I was running php-fpm7 and nginx in an alpine:3.8 docker container. The problem that I faced was the env variables of USER myuser was not getting copied into the USER root

    My entrypoint for docker was

    sudo nginx  # Runs nginx as daemon
    sudo php-fpm7 -F -O  # Runs php-fpm7 in foreground
    

    The solution for this was

    sudo -E nginx
    sudo -E php-fpm7 -F -O
    

    -E option of sudo copies all env variables of current user to the root

    Of course, your php-fpm.d/www.conf file should have clear_env=no

    And FYI, if you're using a daemon service like supervisord they have their own settings to copy the env. For example, supervisord has setting called copy_env=True

提交回复
热议问题