编译安装PHP报错

源码编译安装的PHP,每次运行的时候都报错,提示

PHP Warning:  PHP Startup: Unable to load dynamic library ‘curl.so’ 等一大串的警告

经过N次尝试,终于找到了问题所在,下面是解决方式,仅供参考

PHP版本:

PHP-7.2.13

配置参数:

./configure \

–prefix=/usr/local/php \

–with-config-file-path=/usr/local/php/etc \

–with-apxs2=/usr/bin/apxs \

–with-mcrypt \

–with-curl \

–enable-mysqlnd \

–with-mysqli=mysqlnd –with-openssl \

–with-pdo-mysql=mysqlnd \

–enable-mbstring \

–with-freetype-dir \

–with-jpeg-dir \

–with-png-dir \

–with-zlib –with-libxml-dir=/usr \

–enable-xml –enable-sockets \

–with-mcrypt –with-config-file-path=/etc \

–with-config-file-scan-dir=/etc/php.d \

–disable-fileinfo

Make install 后执行php -v

出现类似以下提示(报错信息格式有重新整理过):

[root@iz8vbg21n2fr3ygt2p4lglz ~]# php -v

PHP Warning:  PHP Startup: Unable to load dynamic library ‘curl.so'(tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/curl.so : cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library ‘fileinfo.so’ (tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/fileinfo.so : cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library ‘json.so'(tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/json.so : cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library ‘mcrypt.so'(tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/mcrypt.so : cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library ‘phar.so'(tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/phar.so : cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library ‘zip.so'(tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/zip.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP 7.2.13 (cli) (built: Dec 13 2018 18:00:04) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

错误信息为:无法加载以下动态库文件 curl.so,fileinfo.so,json.so,mcrypt.so,phar.so,zip.so等

/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/目录下找不到类似的文件或目录

查看php扩展目录发现确实不存在这些文件

1.png

Web 页面查看phpinfo却可以发现这些模块都已加载

2.png

3.png

4.png

执行php -m 也能看到加载的模块

5.png

但每次执行php -v的时候都会抛出以下警告

PHP Warning:  PHP Startup: Unable to load dynamic library ‘curl.so’

PHP Warning:  PHP Startup: Unable to load dynamic library ‘fileinfo.so’

PHP Warning:  PHP Startup: Unable to load dynamic library ‘json.so’

PHP Warning:  PHP Startup: Unable to load dynamic library ‘mcrypt.so’

PHP Warning:  PHP Startup: Unable to load dynamic library ‘phar.so’

查看php.ini问查看extensions 部分,并没有加载任何模块

6.png

上网搜索相关警告信息,能找到的大部分解决方法都是修改/etc/php.ini 文件

把相关的模块注释掉,或者把相关的文件加入php/extensions目录

经过各种尝试研究终于发现了问题的根源

由于编译的时候配置了–with-config-file-scan-dir=/etc/php.d \该参数

导致PHP 启动时会扫描/etc/php.d目录,加载配置文件

查看/etc/php.d目录

7.png

发现警告中的模块对应的配置文件

查看各文件内容

8.png

报错信息中提示的模块都是由这些配置文件启用的

最终解决方案可以将/etc/php.d目录中的这些文件删除

或者将各配置文件中的内容注释掉都可以

执行:mv /etc/php.d/*.ini /root/php.d/

再次执行php -v 那些报错信息终于消失了

9.png

 其实导致该问题的原因跟configure配置参数也有关系, 关于configure配置参数的内容以后有机会再说

编译安装PHP报错

转载请注明来源:幽幽过客_{编译安装PHP报错}