编译安装PHP的一个奇怪错误

​ 今天下午做编译php-fpm的练习,7.1.8,预编译正常,make和make install也正常,就是启动服务的时候报错。仔细检查了所有步骤也没发现哪里不对,后来实在很绝望,无意之中看了下端口发现端口是已经启动了的,这就让人很吃惊,于是尝试了一下使用HTTP服务进行访问,发现PHP服务居然是正常的。但报错依然存在,所以费了一下午的功夫,终于找到了一个妥协的方案。

环境信息

​ PHP的源码是在SOHO的源下载的7.1.8,系统环境是CentOS7.4,编译需要的环境通过以下方式进行解决的。系统中已经存在的服务只有mariadb,版本是10.2.15.

yum install -y bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel php-mysql

预编译及编译安装过程顺利,没有报错,使用的编译选项如下:

./configure --prefix=/app/php \
--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 \
--enable-fpm \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-maintainer-zts \
--disable-fileinfo

安装完成之后在编译目录执行了以下命令:

/root/src/php-7.1.8/build/shtool install -c ext/phar/phar.phar /app/php/bin
ln -s -f phar.phar /app/php/bin/phar
cp php.ini-production /etc/php.ini

然后在PHP的安装目录执行以下命令

cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf

之后通过安装目录下sbin下的php-fpm启动服务

错误信息

第一种错误信息如下:

Starting php-fpm [26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/curl.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/fileinfo.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/fileinfo.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/json.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/json.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/mysql.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/mysqli.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/pdo.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/pdo_mysql.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/pdo_sqlite.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/pdo_sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/phar.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/phar.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/sqlite3.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/sqlite3.so: cannot open shared object file: No such file or directory in Unknown on line 0
[26-Jun-2018 08:47:41] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/app/php/lib/php/extensions/no-debug-zts-20160303/zip.so' - /app/php/lib/php/extensions/no-debug-zts-20160303/zip.so: cannot open shared object file: No such file or directory in Unknown on line 0
 done

通过报错信息发现php程序在/app/php/lib/php/extensions/no-debug-zts-20160303目录下找不到大量的so库文件,后来通过find命令发现所提示的所有的so文件都在/usr/lib64/php/modules/目录下。于是尝试修改/etc/php.ini文件中的一下内容进行尝试。

extension_dir = "/usr/lib64/php/modules/"

重启服务发现依然报错,但信息有所变化。内容如下:

Gracefully shutting down php-fpm . done
Starting php-fpm [26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/curl.so' - /usr/lib64/php/modules/curl.so: undefined symbol: file_globals in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/fileinfo.so' - /usr/lib64/php/modules/fileinfo.so: undefined symbol: zval_used_for_init in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/json.so' - /usr/lib64/php/modules/json.so: undefined symbol: zval_used_for_init in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysql.so' - /usr/lib64/php/modules/mysql.so: undefined symbol: core_globals in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: undefined symbol: executor_globals in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo.so' - /usr/lib64/php/modules/pdo.so: undefined symbol: compiler_globals in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: pdo_mysql: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20160303
These options need to match
 in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlite.so' - /usr/lib64/php/modules/pdo_sqlite.so: undefined symbol: core_globals in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/phar.so' - /usr/lib64/php/modules/phar.so: undefined symbol: compiler_globals in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/sqlite3.so' - /usr/lib64/php/modules/sqlite3.so: undefined symbol: core_globals in Unknown on line 0
[26-Jun-2018 09:04:06] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/zip.so' - /usr/lib64/php/modules/zip.so: undefined symbol: zval_used_for_init in Unknown on line 0
 done

看不太懂,但似乎和PHP的模块有关系,通过百度得到了一点有用的信息,即在/etc/php.d下会有不同的ini文件对应不同的模块。本来想尝试安装对应的模块解决,奈何水平有限,搞不定。于是尝试吧这些配置文件移走。发现问题解决。

总结

PHP有许多的独立模块,这些模块会依赖某些库文件,且每个模块又有对应的配置文件,当模块,配置文件,库文件任一环节出现问题都会出现问题。但是目前以我的水平并不能实质解决这个问题。虽然通过删除配置文件暂时解决,但不能确保在长期使用时的稳定性。


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!