Windows

PHP 在通過 CLI 呼叫時載入擴展,而不是通過 Apache

  • May 23, 2020

對我來說,PHP 僅在從 CLI 呼叫時才能完美載入擴展,但在我通過 Apache 載入頁面時卻不能。

例如,這是 的輸出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

但是,當通過 Apache 執行時:

  1. phpinfo()中,OpenSSL 支持顯示為“已禁用”。

2.extension_loaded("curl")false

3.get_loaded_extensions()不包括curlor OpenSSL

  1. 嘗試使用任何擴展功能失敗。

這是var_dump(get_loaded_extensions());通過 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"
}

你: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:來自https://www.apachelounge.com/的 Apache 2.4.43 Win64

PHP 和 Apache 通過 this in httpd.conf(mod_php) 進行互動:

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

這台機器上只安裝了一個 Apache+PHP。


我試過的:

  1. 確認 PHP 在兩種模式下都使用相同的 ini 文件。如果我從 ini 文件中禁用副檔名,它們就會停止顯示php -m(應該如此)。
  2. (重新)安裝 MS Visual Studio C++ Redistributable 2015-19(x86 和 x64)。
  3. 重新啟動httpd
  4. 重啟電腦。
  5. 重新安裝 PHP 和 Apache。
  6. display_startup_errors=on然後檢查日誌。Apache 和 PHP 錯誤日誌中都沒有相關資訊。
  7. 確認 PHP 正在 ZTS 中執行php.exe -v,“執行緒安全”顯示為phpinfo()通過 Apache 啟用。

請幫忙。我需要這個網路伺服器啟動並執行,這讓我發瘋。

我能夠通過將 Apache Lounge 二進製文件替換為Apache Haus的二進製文件來解決這個問題。

我只是用Apache24新文件夾替換了舊文件夾,但保留了舊conf文件夾。無需進行其他更改。

引用自:https://serverfault.com/questions/1015819