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

Posted on

A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about PHP loads extensions when called through CLI, but not through Apache was one problem in server stack that need for a solution. Below are some tips in manage your windows server when you find problem about windows, php, apache-2.4, extension, .

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.

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.

Leave a Reply

Your email address will not be published.