LAMP架构-PHP动态扩展模块

生产环境中,为保障网站正常运行,不允许再次编译php,那么缺少或漏安装了模块,可以通过单独安装模块的方法来增加到php下面;

查看php加载的模块

/usr/local/php/bin/php -m
类似于apache的-M一样

举例:增加redis.so模块

下载模块

cd /usr/local/src/
wget https://codeload.github.com/phpredis/phpredis/zip/develop

改名和解压

mv develop phpredis-develop.zip
unzip phpredis-develop.zip

生成configure配置文件

/usr/local/php/bin/phpize

注意:必须提前安装autoconf包,不然会告错;
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

安装autoconf包
yum install -y autoconf

指定配置

cd /usr/local/src/phpredis-develop/
./configure --with-php-config=/usr/local/php/bin/php-config

编译安装

make && make install
安装后提示模块安放路径
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/

查询模块的路径

/usr/local/php/bin/php -i |grep extension_dir

extension_dir => /usr/local/php/lib/php/extensions/no-debug-zts-20131226 => /usr/local/php/lib/php/extensions/no-debug-zts-20131226
sqlite3.extension_dir => no value => no value

修改php.ini加载扩展模块

vim /usr/local/php/etc/php.ini
搜索extension= 在后面增加一行
extension=redis.so

检查是否加载redis

/usr/local/php/bin/php -m |grep redis

注意:要想生效,重启apache服务;