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

PHP loads extensions when called through CLI, but not through Apache

· 52CE 我爱测

PHP for me only loads exensions perfectly when called from the CLI, but not when I load pages through Apache. For example, this is the output of php -m : [PHP Modules] bcmath calendar Core ctype curl date dom filter hash iconv js…

问题原文

原帖链接 · undo · CC BY-SA 4.0

PHP for me only loads exensions perfectly when called from the CLI, but not when I load pages through Apache.

For example, this is the output of php -m:

[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
filter
hash
iconv
json
libxml
mysqlnd
openssl
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

However, when run through Apache:
1. In phpinfo(), OpenSSL support shows up as "disabled".
2. extension_loaded("curl") is false
3. get_loaded_extensions() doesn't include curl or OpenSSL.
4. Trying to use any of the extensions's functions fails.

Here's var_dump(get_loaded_extensions()); when running through Apache:

array(28) {
  [0]=>
  string(4) "Core"
  [1]=>
  string(6) "bcmath"
  [2]=>
  string(8) "calendar"
  [3]=>
  string(5) "ctype"
  [4]=>
  string(4) "date"
  [5]=>
  string(6) "filter"
  [6]=>
  string(4) "hash"
  [7]=>
  string(5) "iconv"
  [8]=>
  string(4) "json"
  [9]=>
  string(3) "SPL"
  [10]=>
  string(4) "pcre"
  [11]=>
  string(8) "readline"
  [12]=>
  string(10) "Reflection"
  [13]=>
  string(7) "session"
  [14]=>
  string(8) "standard"
  [15]=>
  string(7) "mysqlnd"
  [16]=>
  string(9) "tokenizer"
  [17]=>
  string(3) "zip"
  [18]=>
  string(4) "zlib"
  [19]=>
  string(6) "libxml"
  [20]=>
  string(3) "dom"
  [21]=>
  string(3) "PDO"
  [22]=>
  string(4) "Phar"
  [23]=>
  string(9) "SimpleXML"
  [24]=>
  string(3) "xml"
  [25]=>
  string(9) "xmlreader"
  [26]=>
  string(9) "xmlwriter"
  [27]=>
  string(14) "apache2handler"
}

OS: Windows 10 1809, up to date.

php -v:

PHP 7.4.5 (cli) (built: Apr 14 2020 16:17:34) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

httpd: Apache 2.4.43 Win64 from https://www.apachelounge.com/

PHP and Apache interacting through this in httpd.conf (mod_php):

LoadModule php7_module "C:/<path_to_PHP>/PHP7/php7apache2_4.dll"

There is only one Apache+PHP install on this machine.


What I've tried:

  1. Confirmed that PHP is using the same ini file in both modes. If I disable extensions from the ini file, they stop showing in php -m (as they should).
  2. (Re)installing MS Visual Studio C++ Redistributable 2015-19 (both x86 and x64).
  3. Restarting httpd.
  4. Restarting PC.
  5. Reinstalling PHP and Apache.
  6. display_startup_errors=on and then checking logs. There is no relevant info in both Apache and PHP error logs.
  7. Confirmed PHP is running in ZTS in php.exe -v, "Thread Safety" shows up as enabled in phpinfo() through Apache.

Please help. I need this webserver up and running, and this is driving me crazy.

已采纳解答

原帖链接 · undo · CC BY-SA 4.0

I was able to solve the issue by replacing the Apache Lounge binaries with ones from Apache Haus.

I just replaced the old Apache24 folder with the new one, but retained the old conf folder. No other changes needed to be made.

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

资料来源与适用范围

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

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

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