Apache2 + PHP-FPM-未定义函数apache_getenv()

问题描述 投票:1回答:1

我有一个大问题,因为几个小时以来,我一直在尝试运行一个在PHP中使用SetENV的项目。当他甚至尝试使用一个简单的函数apache_getenv();

<?php
$ret = apache_getenv("SERVER_ADDR");
echo $ret;
?>

我收到反馈错误消息

Fatal error: Uncaught Error: Call to undefined function apache_getenv() in /var/www/html/env.php:2 Stack trace: #0 {main} thrown in /var/www/html/env.php on line 2

使用php-cli出现同样的错误。我的配置如下。

Apache/2.4.34 (Fedora)
PHP 7.2.15 (cli)

# apachectl -M | grep env
env_module (shared)
setenvif_module (shared)
php environment-variables apache2
1个回答
0
投票

函数apache_getenv()在PHP-FPM中不可用。只需使用getenv()而不是apache_getenv()。

<?php
$ret = getenv("SERVER_ADDR");
echo $ret;
?>

通常现在没有理由立即使用apache_getenv()而不是getenv()。

© www.soinside.com 2019 - 2024. All rights reserved.