首先安装mysqli扩展
cd /usr/local/src/php-7.17/ext/
cd mysqli
/usr/local/php/bin/phpize
./configure --prefix=/usr/local/related/mysqli --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make时提示这个错误:
/usr/local/src/php-7.1.7/ext/mysqli/mysqli_api.c:36:47: 致命错误:ext/mysqlnd/mysql_float_to_double.h:没有那个文件或目录
#include "ext/mysqlnd/mysql_float_to_double.h"
这是因为当前是在mysqli这个目录下进行的编译,这个目录下是肯定没有ext/mysqlnd/mysql_float_to_double.h这个目录及文件的,知道了问题的原因那么解决就简单了
cd /usr/local/src/php-7.17
在这个目录下从新编译安装即可:
./ext/mysqli/configure --prefix=/usr/local/related/mysqli --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make && make install
此外还有两种解决方案:
1,
/usr/local/src/php-7.17/ext/mysqli
# vi mysqli_api.c
把第36行的
#include "ext/mysqlnd/mysql_float_to_double.h"
修改为
#include "/usr/local/src/php-7.17/ext/mysqlnd/mysql_float_to_double.h"
2,
,ln -s mysql/include/* usr/include
ln -s php/include/* usr/include
当成功后会如下:
[root@localhost php-7.1.7]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
Installing header files: /usr/local/php/include/php/
然后ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
[root@localhost php-7.1.7]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
mysqli.so opcache.a opcache.so
就看到mysqli.so
然后打开php.ini
增加:extension=mysqli.so
然后编辑php.ini
extension=mysqli.so
重启php-fpm
service php-fpm restart
make时如果提示:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
则说明没有安装antoconf,安装即可:
cd /usr/local/src
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure --prefix=/usr/local/related/autoconf M4=/usr/local/related/m4/bin/m4 --如果不指定M4的地址,那么需要把M4的bin目录加入环境变量/etc/profile
make && make install
然后将autoconf/bin加入到环境变量再次执行/usr/local/php/bin/phpize就可以生成configure安装文件了
如果没安装m4则checking for GNU M4 that supports accurate traces... configure: error: no acceptable m4 could be found in $PATH.
GNU M4 1.4.5 or later is required; 1.4.11 is recommended
:
# cd /usr/local/src
# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure --prefix=/usr/local/related/m4
make && make install
或者yum安装这两个文件
yum install m4
yum install autoconf
二,
安装PDO扩展
cd /usr/local/src/php-7.1.7/ext
cd pdo_mysql
因为新开了一个xshell窗口,所以重新source /etc/profile,这是因为在其他窗口将autoconf添加到的环境变量,在这个窗口无法使用
然后/usr/local/php/bin/phpize 生成configure 文件
./configure --prefix=/usr/local/related/pdo_mysql --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql --这里与安装mysqli稍有不同,mysqli需要mysql_config的目录,而PDO只指向mysql安装目录即可
make && make install
成功后:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
ls一下:
[root@localhost pdo_mysql]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
mysqli.so opcache.a opcache.so pdo_mysql.so
然后编辑php.ini
extension=pdo_mysql.so
重启php-fpm
service php-fpm restart
三,
安装mysqlnd 扩展
cp config9.m4 config.m4
./configure --prefix=/usr/local/related/mysqlnd
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
解决:
export PHP_OPENSSL_DIR=yes
./configure --prefix=/usr/local/related/mysqlnd --with-openssl-dir=
checking for CRYPTO_free in -lcrypto... no
configure: error: libcrypto not found!
其实第一步不需要解决(configure: error: Cannot find OpenSSL's <evp.h>)最终还是如下解决:
./configure --prefix=/usr/local/related/mysqlnd LDFLAGS=-L/usr/local/related/openssl/lib
所以还是需要看./configure --help
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
应该是把LIBS 与 LDFLAGS弄混了
应该用LDFLAGS来指定未按标准安装(也就是默认路径安装)的软件的库位置
最后:
make && make install
[root@localhost mysqlnd]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
Installing header files: /usr/local/php/include/php/
ls 看下:
[root@localhost mysqlnd]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
mysqli.so mysqlnd.so opcache.a opcache.so pdo_mysql.so
同样修改php.ini即可
extension=mysqlnd.so
重启php-fpm
service php-fpm restart
因为mysqlnd并不是一个php的扩展,所以会报错:
NOTICE: PHP message: PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'mysqlnd.so' in Unknown on line 0
最后猜测这个mysqlnd不用安装也行,只要在php.ini里指定好mysql.sock的位置即可:大约在1023行
pdo_mysql.default_socket=/usr/local/mysql/mysql.sock
当然还有mysqi的,大约在1173行
mysqli.default_socket =/usr/local/mysql/mysql.sock
这样php即可与mysql进行通信