dpjpo746884 2017-11-12 11:18
浏览 31

PHP扩展未通过httpd找到,但可以从CLI找到,使用相同的php.ini

I wanted to use some extensions of PHP 7.1 after installing it and Apache 2.4 and on my Windows 7. I wrote a small test script index.php to call some functions of the given extensions.

<?php
    var_dump(mb_strlen('p'));
    var_dump(mysqli_connect_error());

and uncommented the appropriate lines from the php.ini, like

...
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysqli.dll
;extension=php_oci8_12c.dll  ; Use with Oracle Database 12c Instant Client
...

and configured the extension_dir according to the windows-specific part of the php.ini

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"

extension_dir = "ext" 

I restarted the Apache web server and fetched the http://localhost/index.php. I got the error messages:

Fatal error: Uncaught Error: Call to undefined function mb_strlen() in C:\Program Files\Apache24\htdocs...

which means the extension was not loaded.

I doublechecked that the php.ini I made the modifications in is the same as the phpinfo() displayed in the browser:

Loaded Configuration File    C:\Program Files\php\php.ini 

On the contrary, if I started the same index.php not via web server but from the command line then I got different output:

C:\Program Files\Apache24\htdocs>"C:\Program Files\php\php.exe" index.php
int(1)
NULL

which means the extensions were loaded properly.

The command line PHP uses the same php.ini:

c:\Program Files\Apache24\htdocs>php -i|find "Loaded Configuration File"
Loaded Configuration File => C:\Program Files\php\php.ini

How can it be that the same php.ini file loads the extensions from command line but does not load them when used via the web server?

  • 写回答

1条回答 默认 最新

  • douhan9467 2017-11-12 11:38
    关注

    Contrary to the description in the php.ini, the extension_dir should be specified with a full path, not just a relative one. Changing the line in php.ini from

    extension_dir = "ext"
    

    to

    extension_dir = "C:/Progra~1/php/ext"
    

    and restarting the web server solved the problem.

    NB: I used the DOS-8.3 path instead of "C:/Program Files/php/ext" because according to the php-7.1.11-Win32-VC14-x64.zip\install.txt manual, it does not like paths containing spaces:

    You may choose a different location but do not have spaces in the path (like C:\Program Files\PHP) as some web servers will crash if you do.

    The path I referred to doesn't contain any spaces so I don't think I did anything wrong. Despite this, I am not sure how it would work if I had installed php to the default directory c:\php but it seems that defining the full path is a more secure way.

    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果