VPS或云服务器安装php pdo_mysql扩展全过程

一 ,用ZendFramework就需要用到pdo,php安装好后默认是没有启用pdo_mysql的,所以需要添加该模块,解决办法如下:

首先到php的源码包下找到pdo_mysql的源码,或者重新下载pdo_mysql源码

①如果是php源码则路径为:/home/corey/Downloads/php-5.3.1/ext/pdo_mysql ,/home/corey/Downloads/php-5.3.1为你源码所在路径

②如果是重新下载的pdo_mysql,则执行以下操作

二,首先进入下载目录 cd /home/corey/Downloads (该目录是你下载保存pdo_mysql源码包的目录)

PDO_MYSQL源码包URL:http://pecl.php.net/package/PDO_MYSQL

wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

①解压源码

tar -xzvf PDO_MYSQL-1.0.2.tgz (我下的是1.0.2的版本),
[root@cms-test software]# tar zxvf PDO_MYSQL-1.0.2.tgz
package2.xml
PDO_MYSQL-1.0.2/config.m4
PDO_MYSQL-1.0.2/CREDITS
PDO_MYSQL-1.0.2/mysql_driver.c
PDO_MYSQL-1.0.2/mysql_statement.c
PDO_MYSQL-1.0.2/pdo_mysql.c
PDO_MYSQL-1.0.2/php_pdo_mysql.h
PDO_MYSQL-1.0.2/php_pdo_mysql_int.h
PDO_MYSQL-1.0.2/php_pdo_mysql_sqlstate.h

②进入源码包

cd PDO_MYSQL-1.0.2

[root@cms-test PDO_MYSQL-1.0.2]# ls
config.m4 CREDITS mysql_driver.c mysql_statement.c pdo_mysql.c php_pdo_mysql.h php_pdo_mysql_int.h

执行以下操作 :

#/usr/local/php/bin/phpize (/usr/local/php/ 是php的安装目录)

Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

#./configure --with-php-config=/usr/local/php/bin/php-config

在这里遇到来一个问题如下:

A error: Cannot find MySQL header files under

这是因为没找到mysql的安装目录,解决办法为执行以下命令:

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql(/usr/local/mysql为mysql的安装目录) #我的MySQL数据库默认安装在/usr/share/mysql
#在配置的时候还出现not find libmysqlclient.so
#解决方案是,在/usr/lib/中找到libmysqlclient.so文件并且拷到相应的缺少该文件目录下面

B 执行时报错如下;

configure: warning: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for MySQL support for PDO... yes, shared
checking for mysql_config... not found
configure: error: Cannot find MySQL header files under

解决办法:

cp /usr/local/mysql/bin/mysql_config /usr/bin

③再执行以下命令

make
[root@cms-test PDO_MYSQL-1.0.2]#make

执行时报错如下:

/software/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:25:19: error: mysql.h: No such file or directory
In file included from /software/PDO_MYSQL-1.0.2/pdo_mysql.c:31:
/software/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:36: error: expected specifier-qualifier-list before 'MYSQL'
/software/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:48: error: expected specifier-qualifier-list before 'MYSQL_FIELD'
/software/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:53: error: expected specifier-qualifier-list before 'MYSQL_RES'
make: *** [pdo_mysql.lo] Error 1

解决办法:

yum install mysql-devel

#make install

执行完后会提示以下,说明成功:

三,修改php.ini;

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "pdo_mysql.so"

重启apache,到此安装完成,可以查看phpinfo.php里找到对应的pdo_mysql。

加载中...
加载中...