【问题标题】:Apache2 + PHP-FPM - undefined function apache_getenv()Apache2 + PHP-FPM - 未定义函数 apache_getenv()
【发布时间】:2019-03-14 21:13:34
【问题描述】:

我有一个大问题,因为几个小时以来我都在尝试运行一个在 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.ini 中启用了吗?
  • 是的,variables_order = "EGPCS"
  • 检查是否不在 disabled_functions 中
  • disable_functions 为空。我不知道定价是否在于 php-fpm。但也有 clear_env = no

标签: php environment-variables apache2


【解决方案1】:

函数 apache_getenv() 不适用于 PHP-FPM。 只需使用 getenv() 而不是 apache_getenv()。

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

现在通常没有理由使用 apache_getenv() 代替 getenv()。

【讨论】:

  • 注意:getenv() 适用于 SERVER_ADDR 但不适用于 SSL_PROTOCOL
  • 你是对的,但你可以使用 $ret = getenv("REQUEST_SCHEME");它将返回“http”或“https”。
猜你喜欢
  • 2016-02-20
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 2017-08-31
  • 2012-02-09
  • 1970-01-01
  • 2013-05-12
  • 2017-04-25
相关资源
最近更新 更多