大网数据广告活动
服务器运维问答

Configure php-fpm to access environment variables in docker

· 52CE 我爱测

I'm running php7-fpm in a docker container. However my php scripts aren't able to access environments variables set in my docker-compose file. getenv('MY_ENV_VAR') returns FALSE . I've changed /etc/php/7.0/fpm/pool.d/www.conf to …

问题原文

原帖链接 · Aidan Ewen · CC BY-SA 3.0

I'm running php7-fpm in a docker container. However my php scripts aren't able to access environments variables set in my docker-compose file. getenv('MY_ENV_VAR') returns FALSE.

I've changed /etc/php/7.0/fpm/pool.d/www.conf to include clear_env = no and restarted with service php7.0-fpm restart but my environment variables start aren't there.

I've also tried editing /etc/php/7.0/fpm/php.ini includes the line variables_order = "EGPCS".

When I exec into my container on a bash shell I can see that my variables exist. It's just that they're not accessible in my php scripts.

What am I missing?

社区高分解答

原帖链接 · Thiago Pereira · CC BY-SA 4.0

This is a PHP-FPM prank.

  • Setup the clear_env = no on /etc/php/7.2/fpm/pool.d/www.conf, so;

On Dockerfile start de php-fpm with init.d, not use service.
Ex:

CMD /etc/init.d/php7.2-fpm start && nginx -g 'daemon off;'

Check environment variables now

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。