0%

php编译pdo_mysql扩展记录

这次作死,直接用默认配置安装了php。什么扩展都没有添加。结果一直在编译缺失的各种扩展。但是最后还是失败了,仅用做记录用。

在编译到pdo_mysql扩展的时候,就搞不定了。

在进行make操作的时候,出现了如下错误:

1
/usr/local/src/php-7.0.14/ext/pdo_mysql/php_pdo_mysql_int.h:27:34: 致命错误:ext/mysqlnd/mysqlnd.h:没有那个文件或目录
2
 # include "ext/mysqlnd/mysqlnd.h"
3
                                  ^
4
编译中断。
5
make: *** [pdo_mysql.lo] 错误 1

这是走的弯路

我以为是mysqlnd没有编译,我接着去编译mysqlnd扩展了。

然后在./configure的时候,结果又提示我:

1
configure: error: Cannot find OpenSSL's <evp.h>

我以为是openssl-devel没有安装,我接着安装openssl-devel:

1
[root@bogon mysqlnd]# yum install openssl openssl-devel
2
已加载插件:fastestmirror
3
Loading mirror speeds from cached hostfile
4
 * base: mirror.bit.edu.cn
5
 * epel: mirrors.tuna.tsinghua.edu.cn
6
 * extras: mirror.bit.edu.cn
7
 * updates: mirror.bit.edu.cn
8
软件包 1:openssl-1.0.1e-60.el7.x86_64 已安装并且是最新版本
9
软件包 1:openssl-devel-1.0.1e-60.el7.x86_64 已安装并且是最新版本
10
无须任何处理

结果提示我已经安装了,那我强行指定路径吧:

1
[root@bogon mysqlnd]# ./configure --with-openssl=/usr/include/openssl
2
configure: WARNING: unrecognized options: --with-openssl
3
checking for grep that handles long lines and -e... /usr/bin/grep
4
checking for egrep... /usr/bin/grep -E
5
checking for a sed that does not truncate output... /usr/bin/sed
6
checking for cc... cc
7
checking whether the C compiler works... yes
8
checking for C compiler default output file name... a.out
9
checking for suffix of executables... 
10
checking whether we are cross compiling... no
11
checking for suffix of object files... o
12
checking whether we are using the GNU C compiler... yes
13
checking whether cc accepts -g... yes
14
checking for cc option to accept ISO C89... none needed
15
checking how to run the C preprocessor... cc -E
16
checking for icc... no
17
checking for suncc... no
18
checking whether cc understands -c and -o together... yes
19
checking for system library directory... lib
20
checking if compiler supports -R... no
21
checking if compiler supports -Wl,-rpath,... yes
22
checking build system type... x86_64-unknown-linux-gnu
23
checking host system type... x86_64-unknown-linux-gnu
24
checking target system type... x86_64-unknown-linux-gnu
25
checking for PHP prefix... /usr/local/php
26
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
27
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012
28
checking for PHP installed headers prefix... /usr/local/php/include/php
29
checking if debug is enabled... no
30
checking if zts is enabled... no
31
checking for re2c... no
32
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
33
checking for gawk... gawk
34
checking whether to enable mysqlnd... yes, shared
35
checking whether to disable compressed protocol support in mysqlnd... yes
36
checking for the location of libz... no
37
checking for DSA_get_default_method in -lssl... no
38
checking for X509_free in -lcrypto... yes
39
checking for pkg-config... /usr/bin/pkg-config
40
configure: error: Cannot find OpenSSL's <evp.h>

结果还是不行,这下两边路都走不通了,我就去网上查询了。结果还是查询不到什么有用的资料

转回正道

我后来想,我直接改源码试试看呢,把include加载文件写成绝对目录。

说干就干

我先看看这个报错的地方。

文件在/usr/local/src/php-7.0.14/ext/pdo_mysql/php_pdo_mysql_int.h:27:34

我打开该文件,修改第27行的内容:

1
#       include "ext/mysqlnd/mysqlnd.h"
2
#       include "ext/mysqlnd/mysqlnd_libmysql_compat.h"

我的源代码的目录是/usr/local/src/php-7.0.14/,于是我就改成如下所示:

1
#       include "/usr/local/src/php-7.0.14/ext/mysqlnd/mysqlnd.h"
2
#       include "/usr/local/src/php-7.0.14/ext/mysqlnd/mysqlnd_libmysql_compat.h"

我再进行编译:

1
[root@bogon pdo_mysql]# make clean
2
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
3
find . -name \*.lo -o -name \*.o | xargs rm -f
4
find . -name \*.la -o -name \*.a | xargs rm -f 
5
find . -name \*.so | xargs rm -f
6
find . -name .libs -a -type d|xargs rm -rf
7
rm -f libphp.la       modules/* libs/*
8
[root@bogon pdo_mysql]# make
9
/bin/sh /usr/local/src/php-7.0.14/ext/pdo_mysql/libtool --mode=compile cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c -o pdo_mysql.lo 
10
mkdir .libs
11
 cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c  -fPIC -DPIC -o .libs/pdo_mysql.o
12
In file included from /usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c:32:0:
13
/usr/local/src/php-7.0.14/ext/pdo_mysql/php_pdo_mysql_int.h:69:39: 致命错误:ext/mysqlnd/mysqlnd_debug.h:没有那个文件或目录
14
 #include "ext/mysqlnd/mysqlnd_debug.h"
15
                                       ^
16
编译中断。
17
make: *** [pdo_mysql.lo] 错误 1

发现有效果,报错的地方变了,我接着改,这里提示报错的地方还是:/usr/local/src/php-7.0.14/ext/pdo_mysql/php_pdo_mysql_int.h:69:39,但是行数编程69了,我把69行改成如下所示:

1
#include "/usr/local/src/php-7.0.14/ext/mysqlnd/mysqlnd_debug.h"

继续,发现报错信息又变了:

1
[root@bogon pdo_mysql]# make clean
2
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
3
find . -name \*.lo -o -name \*.o | xargs rm -f
4
find . -name \*.la -o -name \*.a | xargs rm -f 
5
find . -name \*.so | xargs rm -f
6
find . -name .libs -a -type d|xargs rm -rf
7
rm -f libphp.la       modules/* libs/*
8
[root@bogon pdo_mysql]# make 
9
/bin/sh /usr/local/src/php-7.0.14/ext/pdo_mysql/libtool --mode=compile cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c -o pdo_mysql.lo 
10
mkdir .libs
11
 cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c  -fPIC -DPIC -o .libs/pdo_mysql.o
12
/usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c:64:45: 致命错误:ext/mysqlnd/mysqlnd_reverse_api.h:没有那个文件或目录
13
 #include "ext/mysqlnd/mysqlnd_reverse_api.h"
14
                                             ^
15
编译中断。
16
make: *** [pdo_mysql.lo] 错误 1

我将文件/usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c:64:45改成如下所示:

1
#include "/usr/local/src/php-7.0.14/ext/mysqlnd/mysqlnd_reverse_api.h"

继续编译:

1
[root@bogon pdo_mysql]# make clean
2
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
3
find . -name \*.lo -o -name \*.o | xargs rm -f
4
find . -name \*.la -o -name \*.a | xargs rm -f 
5
find . -name \*.so | xargs rm -f
6
find . -name .libs -a -type d|xargs rm -rf
7
rm -f libphp.la       modules/* libs/*
8
[root@bogon pdo_mysql]# make 
9
/bin/sh /usr/local/src/php-7.0.14/ext/pdo_mysql/libtool --mode=compile cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c -o pdo_mysql.lo 
10
mkdir .libs
11
 cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-7.0.14/ext/pdo_mysql/pdo_mysql.c  -fPIC -DPIC -o .libs/pdo_mysql.o
12
/bin/sh /usr/local/src/php-7.0.14/ext/pdo_mysql/libtool --mode=compile cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-7.0.14/ext/pdo_mysql/mysql_driver.c -o mysql_driver.lo 
13
 cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-7.0.14/ext/pdo_mysql/mysql_driver.c  -fPIC -DPIC -o .libs/mysql_driver.o
14
/bin/sh /usr/local/src/php-7.0.14/ext/pdo_mysql/libtool --mode=compile cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-7.0.14/ext/pdo_mysql/mysql_statement.c -o mysql_statement.lo 
15
 cc -I/usr/local/php/include/php/ext -I -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/usr/local/src/php-7.0.14/ext/pdo_mysql -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-7.0.14/ext/pdo_mysql/mysql_statement.c  -fPIC -DPIC -o .libs/mysql_statement.o
16
/bin/sh /usr/local/src/php-7.0.14/ext/pdo_mysql/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/php-7.0.14/ext/pdo_mysql/include -I/usr/local/src/php-7.0.14/ext/pdo_mysql/main -I/usr/local/src/php-7.0.14/ext/pdo_mysql -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o pdo_mysql.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/php-7.0.14/ext/pdo_mysql/modules  pdo_mysql.lo mysql_driver.lo mysql_statement.lo 
17
cc -shared  .libs/pdo_mysql.o .libs/mysql_driver.o .libs/mysql_statement.o   -Wl,-soname -Wl,pdo_mysql.so -o .libs/pdo_mysql.so
18
creating pdo_mysql.la
19
(cd .libs && rm -f pdo_mysql.la && ln -s ../pdo_mysql.la pdo_mysql.la)
20
/bin/sh /usr/local/src/php-7.0.14/ext/pdo_mysql/libtool --mode=install cp ./pdo_mysql.la /usr/local/src/php-7.0.14/ext/pdo_mysql/modules
21
cp ./.libs/pdo_mysql.so /usr/local/src/php-7.0.14/ext/pdo_mysql/modules/pdo_mysql.so
22
cp ./.libs/pdo_mysql.lai /usr/local/src/php-7.0.14/ext/pdo_mysql/modules/pdo_mysql.la
23
PATH="$PATH:/sbin" ldconfig -n /usr/local/src/php-7.0.14/ext/pdo_mysql/modules
24
----------------------------------------------------------------------
25
Libraries have been installed in:
26
   /usr/local/src/php-7.0.14/ext/pdo_mysql/modules
27
28
If you ever happen to want to link against installed libraries
29
in a given directory, LIBDIR, you must either use libtool, and
30
specify the full pathname of the library, or use the `-LLIBDIR'
31
flag during linking and do at least one of the following:
32
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
33
     during execution
34
   - add LIBDIR to the `LD_RUN_PATH' environment variable
35
     during linking
36
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
37
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'
38
39
See any operating system documentation about shared libraries for
40
more information, such as the ld(1) and ld.so(8) manual pages.
41
----------------------------------------------------------------------
42
43
Build complete.
44
Don't forget to run 'make test'.

这样就成功了。接下来我们就可以继续make install进行安装了。

1
[root@bogon pdo_mysql]# make install
2
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/

我们修改一下配置文件,添加下面的内容到配置文件中:

1
extension=pdo_mysql.so

然后我们测试扩展是否安装成功了:

1
[root@bogon pdo_mysql]# php -m
2
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
3
4
Warning: Module 'PDO' already loaded in Unknown on line 0
5
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/pdo_mysql.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/pdo_mysql.so: undefined symbol: mysqlnd_allocator in Unknown on line 0
6
7
Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/pdo_mysql.so' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/pdo_mysql.so: undefined symbol: mysqlnd_allocator in Unknown on line 0

报错了。看来我们还需要mysqlnd扩展:

然后还是提示找不到openssl的错误。

我接着去网上搜了一下。

还是找不到答案,我查了一下,这个好像是一个bug,一直没有修复。

解决办法只能是重装php来解决了。