Home >Backend Development >PHP Tutorial >linux - mac 下命令行执行 php a.php 报错,php扩展貌似没有加载,怎么加载?

linux - mac 下命令行执行 php a.php 报错,php扩展貌似没有加载,怎么加载?

WBOY
WBOYOriginal
2016-06-06 20:41:471237browse

【 补充:代码层phpinfo(),扩展信息均正常显示】

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so, 9): image not found in Unknown on line 0

回复内容:

【 补充:代码层phpinfo(),扩展信息均正常显示】

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/mongo.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/memcache.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/redis.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/zmq.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so' - dlopen(/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so, 9): image not found in Unknown on line 0

配置文件php.ini,extension_dir设置错误。
/usr/local/Cellar/php54/5.4.33/lib/php/extensions/no-debug-non-zts-20100525/该目录下并没有memcache.so等文件,在其他目录里面

终端 php -i |grep mongo查看你的扩展是否安装成功。
如果没有 需要下载 扩展并编译安装 安装完成后需要在php.ini中添加模块

可能1:命令行下php.ini没有自动加载,可以手动指定

<code>php  -c  /etc/php.ini a.php
</code>

可能2: 命令行下默认执行的php与web所执行的不一致,查看phpinfo中的php路径,与命令行中的是否一致,不一致的话要改成一致的,或者给两个版本都安装上对于的扩展

<code>which php #看路径
</code>

推荐使用brew安装,省去很多麻烦

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn