PDO_MYSQL的安装

 真是不好意思,之前的那篇lnmp的搭建并没有安装pdo_mysql的扩展,就导致了我想创建pdo连接的时候,他告诉我,could not find driver,一开始我以为是框架原因,测试了半天,发现PDO drivers,没有mysql,心累,本来以为得重新编译安装了,百度了半天发现不用重新编译,用phpize就可以解决这个问题,那么,我就尝试安装吧!

1、下载php_mysql安装包;

 

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

2、接下来解压,解压到指定的文件夹,我就放到了/usr/local/src/下面,

 

tar zxvf PDO_MYSQL-1.0.2.tgz -C /usr/local/src 

3、进入此文件夹:

 

 

cd /usr/local/src/PDO_MYSQL-1.0.2/


4、使用phpize功能进行前奏,因为我的php安装在了/usr/local/php/,所以我的phpize也就在这了:

 

 

 /usr/local/php/bin/phpize

5、!!!敲黑板!!划重点,来了,进行编译安装:

 

 

./configure --with-php-config=/usr/local/php/bin/php-config  --with-pdo-mysql=/usr/local/mysql/

6、最后的步骤:

 

 

make && make install

7、突然来了一个bug,fuck,解决吧,很简单报了一个这样的错误,挺长的,我不管,我只看到了最后一句,意思就是因为在编译时需要 MySQL 的头的文件,而它按默认搜索找不到头文件的位置,所以才出现这个问题。:

 

 

 cc -I -I/usr/local/mysql//include -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -I. -I/usr/local/src/PDO_MYSQL-1.0.2 -DPHP_ATOM_INC -I/usr/local/src/PDO_MYSQL-1.0.2/include -I/usr/local/src/PDO_MYSQL-1.0.2/main -I/usr/local/src/PDO_MYSQL-1.0.2 -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/PDO_MYSQL-1.0.2/pdo_mysql.c  -fPIC -DPIC -o .libs/pdo_mysql.o
In file included from /usr/local/src/PDO_MYSQL-1.0.2/pdo_mysql.c:31:
/usr/local/src/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:25:19: error: mysql.h: No such file or directory
In file included from /usr/local/src/PDO_MYSQL-1.0.2/pdo_mysql.c:31:
/usr/local/src/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:36: error: expected specifier-qualifier-list before ‘MYSQL’
/usr/local/src/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:48: error: expected specifier-qualifier-list before ‘MYSQL_FIELD’
/usr/local/src/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

8、解决方案,通过软连接把MySQL头文件对应到/usr/local/include/下就ok了,举个栗子我的MySQL安装文件位于/usr/local/mysql,将 /usr/local/server/mysql/include/ 目录下的 MySQL 头文件链接到 /usr/local/include/ 的目录下,那么就执行以下命令:

 

ln -s /usr/local/server/mysql/include/* /usr/local/include/

9、检查一下pdo_mysql.so是否存在,恩,在了:

 

 

cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

10、编辑一下php.ini:

 

 

vi /etc/php.ini

11、添加扩展:

 

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so
或者 extension=pdo_mysql.so 

12、重启nginx,php-fpm,mysql;


ok,解决了,回头看一下phpinfo,恩,一切都有了!



 

你可能感兴趣的:(php,运维,linux,nginx)