一、环境
LAMP都是源码安装,php安装的时候没有配置pdo_mysql和mysqli,pdo是php5默认带的。
PHP5的源码都在,只需要把php5的模块功能扩展就可以了。
php源码目录:/usr/local/src/php-5.2.10
php安装目录:/usr/local/php/
php源码配置文件:/usr/local/php/bin/php-config
php程序配置文件:/usr/local/php/etc/php.ini
二、模块的编译安装
[[email protected] ~] cd /usr/local/src/php-5.2.10/ext/pdo [[email protected] pdo] /usr/local/php/bin/phpize [[email protected] pdo] ./configure –with-php-config=/usr/local/php/bin/php-config [[email protected] pdo] make [[email protected] pdo] make test [[email protected] pdo] make install [[email protected] ~] cd /usr/local/src/php-5.2.10/ext/pdo_mysql [[email protected] pdo_mysql] /usr/local/php/bin/phpize [[email protected] pdo_mysql] ./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo- mysql=/usr/local/mysql [[email protected] pdo_mysql] make [[email protected] pdo_mysql] make test [[email protected] pdo_mysql] make install [[email protected] ~] cd /usr/local/src/php-5.2.10/ext/mysqli [[email protected] mysqli] /usr/local/php/bin/phpize [[email protected] mysqli] ./configure –with-php-config=/usr/local/php/bin/php-config –with- mysqli=/usr/local/mysql/bin/mysql_config [[email protected] mysqli] make [[email protected] mysqli] make test [[email protected] mysqli] make install
备注:
注意安装时目录的位置一定要正确,不然模块不能加载。
命令/usr/local/php/bin/phpize必须在安装的目录执行。
安装完后会产生三个so模块:
/usr/local/php/lib/php/extensions/no-debug-zts-20060613/pdo.so /usr/local/php/lib/php/extensions/no-debug-zts-20060613/pdo_mysql.so /usr/local/php/lib/php/extensions/no-debug-zts-20060613/mysqli.so
三、PHP配置文件的配置
更改php.ini配置,添加模块:
vi /usr/local/php/etc/php.ini extension=/usr/local/php/lib/php/extensions/no-debug-zts-20060613/pdo.so extension=/usr/local/php/lib/php/extensions/no-debug-zts-20060613/pdo_mysql.so extension=/usr/local/php/lib/php/extensions/no-debug-zts-20060613/mysqli.so
服务重启:
service mysqld restart
service apached restart
四、环境测试:
1、php5环境查看(建立php函数):
vi phpinfo.php <?php phpinfo(); ?>
访问phpinfo.php页面,查看模块扩展存不存在:
http://127.0.0.1/phpinfo.php
备注:
如果函数不能使用,更改配置开放函数的使用权限。
[[email protected] ~] vi /usr/local/php/etc/php.ini disable_functions = phpinfo,passthru,…..
删除phpinfo这个函数保存即可。
[[email protected] ~] service apached restart
2、mysqli连接测试(建立网页测试连接)。
vi mysqlidb.php $mysqli = new mysqli(“localhost”, “dbusername”, “dbpassword”, “dbname”); /* check connection */ if (mysqli_connect_errno()) { printf(“Connect failed: %s\n”, mysqli_connect_error()); exit(); } printf(“Host information: %s\n”, $mysqli->host_info); /* close connection */ $mysqli->close(); ?>
访问建立的php测试页:
http://127.0.0.1/mysqlidb.php