linux下的php扩展与windows下的扩展安装有些不同。下面就拿在linux下扩展php的pdo,pdo_mysql模块来说明一下
由于php7默认去掉了mysql扩展,那么我们自己动手。 1.在php的原码安装包里,进入到etc/pdo_mysql里。假设你的php是安装在/usr/local/php里的。执行/usr/local/php/bin/phpize 2. 进行编译。./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql (假设你的mysql是安装在/usr/local/mysql) 3.编译安装。make,make install。 4.到了第3步的时候。在/usr/local/php/lib/php/extensions里就会多了个no-debug-non-zts-20050922(类似名称)文件夹,它里面就生成了一个pdo_mysql.so 5.修改php.ini,加入扩展语句extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922(类似名称)/pdo_mysql.so" 6.重启apache/nginx。OK扩展完成 7.安装pdo的方法与pdo_mysql的方法一样.但是要注意在这个安装过程中如果系统没有aclocal命令,那么请先安装这个命令,这个命令在autoconf包里。
./configure 的时候可能遇到的问题
[root@localhost pdo_mysql]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/ --with-zlib-dir=/usr/local/lib checking for egrep... grep -E checking for a sed that does not truncate output... /bin/sed checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ANSI C... none needed checking whether gcc and cc understand -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu checking for PHP prefix... /usr/local/php 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 checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 checking for PHP installed headers prefix... /usr/local/php/include/php checking for re2c... re2c checking for re2c version... 0.12.3 (ok) checking for gawk... gawk checking for MySQL support for PDO... yes, shared checking for the location of libz... /usr/local/lib checking for mysql_config... /usr/local/mysql//bin/mysql_config checking for mysql_query in -lmysqlclient... no checking for mysql_query in -lmysqlclient... (cached) no configure: error: PDO_MYSQL configure failed. Please check config.log for more information.
解决方法:
1、用php官方的mysqlnd。--with-pdo-mysql=mysqlnd ,php 5.3+版本都可以。
2、 checking for mysql_query in -lmysqlclient... no checking for mysql_query in -lmysqlclient... (cached) no
先安装mysqlclient 就好了.
make && make install 遇到的问题
ext/mysqlnd/mysqlnd.h:没有那个文件或目录 #include "ext/mysqlnd/mysqlnd.h"
解决方法:
1、自己查看mysqlnd是否存在,不存在可能是缺mysql的开发包, 装一下 *mysql*-dev, *mysql*-devel 之类的试一下
2、如果有文件,根据错误找到相应的位置,然后修改路径ext/mysqlnd/mysqlnd.h ,我的是退后了两级../../ext/mysqlnd/mysqlnd.h (根据自己文件位置确定)