PHP编译安装扩展(mysqli,pdo-mysql)
qunying.liu
201410.30
1.环境说明:
系统:CentOS 6.3 64位 Linux
PHP版本:5.3.13
Mysql版本:5.5.26
PHP安装目录:/usr/local/php
PHP配置文件:/usr/local/php/etc/php.ini
PHP扩展目录:/usr/local/php/lib/php/extensions/no-debug-non-zts-20090624/
MySQL安装目录:/usr/local/mysql
php.ini:
; Directory in which the loadable extensions (modules) reside. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090624/"
2.编译安装扩展:
PHP扩展安装pdo_mysql模块,在Linux系统下进行,按以下步骤即可完成模块安装:
# tar -zxvf php-5.3.13.tgz
# cd php-5.3.13/ext/pdo_mysql
# /usr/local/php/bin/phpize
# cp /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql-config=/usr/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --enable-pdo=shared
# make && make install
备注:make test的时候会报错,但不影响编译安装的正常进行,可以忽略:
===================================================================== PHP : /usr/local/php/bin/php PHP_SAPI : cli PHP_VERSION : 5.3.13 ZEND_VERSION: 2.2.0 PHP_OS : Linux - CentOS 6.3 Linux X64 INI actual : /usr/local/php/etc/php.ini More .INIs : CWD : /usr/local/src/php/php-5.3.13/ext/pdo_mysql Extra dirs : ===================================================================== Running selected tests. SKIP PDO MySQL Bug #33689 (query() execute() and fetch() return false on valid select queries) [tests/bug_33689.phpt] reason: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) SKIP PDO MySQL Bug #37445 (Premature stmt object destruction) [tests/bug_37445.phpt] reason: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) SKIP PDO MySQL Bug #39483 (Problem with handling of \ char in prepared statements) [tests/bug_39483.phpt] reason: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) SKIP PDO MySQL Bug #41698 (float parameters truncated to integer in prepared statements) [tests/bug_41698.phpt] reason: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) PHP Warning: opendir(ext/pdo/tests): failed to open dir: No such file or directory in /usr/local/src/php/php-5.3.13/ext/pdo_mysql/run-tests.php on line 597 ERROR: cannot open directory: ext/pdo/tests make: [test] Error 1 (ignored)
PHP扩展安装mysqli模块,在Linux系统下进行,按以下步骤即可完成模块安装:
# tar -zxvf php-5.3.13.tgz
# cd php-5.3.13/ext/mysqli
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli= /usr/bin/mysql_config
# make && make install
配置过程报错:
checking for mysql_set_server_option in -lmysqlclient... no configure: error: wrong mysql library version or lib not found. Check config.log for more information. configure: failed program was: | /* confdefs.h. */ | | #define PACKAGE_NAME "" | #define PACKAGE_TARNAME "" | #define PACKAGE_VERSION "" | #define PACKAGE_STRING "" | #define PACKAGE_BUGREPORT "" | /* end confdefs.h. */ | | /* Override any gcc2 internal prototype to avoid an error. */ | #ifdef __cplusplus | extern "C" | #endif | /* We use char because int might match the return type of a gcc2 | builtin and then its argument prototype would still apply. */ | char mysql_set_server_option (); | int | main () | { | mysql_set_server_option (); | ; | return 0; | } configure:3473: result: no configure:3801: error: wrong mysql library version or lib not found. Check config.log for more information.
没有找到mysql库文件,说明mysql环境变量设置不正确或者mysql-devel库未安装。
yum -y install mysql-devel 或 源码编译安装mysql-devel
3.修改PHP配置文件
sed -i '/pdo_mysql.so/d' /usr/local/php/etc/php.ini
sed -i '/^extension_dir/a extension = "pdo_mysql"' /usr/local/php/etc/php.ini
sed -i '/mysqli.so/d' /usr/local/php/etc/php.ini
sed -i '/^extension_dir/a extension = "mysqli"' /usr/local/php/etc/php.ini
4.重启apache或nginx,让配置生效:
/usr/local/apache/bin/apachectl -k restart 或 /etc/init.d/httpd restart
/usr/local/nginx/sbin/nginx -s reload 或 /etc/init.d/nginx restart
备注:
在编译 php 的时候加上了 这个--with-mysqli=/usr/local/mysql/bin/mysql_config
所报错误是 configure: error: wrong mysql library version or lib not found
在编译的时候 直接 写--with-mysqli 不在添加路径,因为php本身有这个模块,不用再添加mysql 的配置文件路径。