PHP动态扩展模块安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP动态扩展模块安装相关的知识,希望对你有一定的参考价值。

php扩展模块安装

编译httpd时,有涉及动态和静态模块,PHP也一样有静态与动态之分,之前所涉及到的PHP安装都全部为静态,并没有任何动态的模块,所谓动态,就是一个独立存在的.so文件,在httpd中PHP就是以动态模块的形式被加载的。PHP一旦编译完成后,要想再增加一个功能的话,要么重新编译PHP,要么直接编译一个扩展模块(生成一个.so文件),然后在php.ini中配置一下,就可以被加载使用了。

1、查看PHP加载的模块

[[email protected] ~]# /usr/local/php/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

2、安装一个PHP扩展模块(redis模块)

[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
[[email protected] src]# mv develop phpredis-develop.zip
[[email protected] src]# unzip phpredis-develop.zip 
[[email protected] src]# cd phpredis-develop/
[[email protected] phpredis-develop]# /usr/local/php/bin/phpize      //目的是生成configure文件
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
//报错Cannot find autoconf,需要安装一些autoconf

[[email protected] phpredis-develop]# yum install -y autoconf
[[email protected] phpredis-develop]# /usr/local/php/bin/phpize 
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

[[email protected] phpredis-develop]# ./configure --with-php-config=/usr/local/php/bin/php-config
[[email protected] phpredis-develop]# make
[[email protected] phpredis-develop]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
//make install会把编译好的redis放到这个目录下,该目录为扩展模块存放目录

[[email protected] phpredis-develop]# /usr/local/php/bin/php -i | grep -i 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中修改目录

[[email protected] phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
opcache.so  redis.so

3、修改PHP配置文件,使扩展模块生效

[[email protected] phpredis-develop]# vim /usr/local/php/etc/php.ini    //添加以下内容

extension = redis.so

[[email protected] phpredis-develop]# /usr/local/php/bin/php -m | grep redis    //查看是否加载了redis
redis

以上是关于PHP动态扩展模块安装的主要内容,如果未能解决你的问题,请参考以下文章

88.PHP扩展模块安装

php动态扩展模块安装

LAMP-php动态扩展模块安装

LAMP架构-PHP动态扩展模块

PHP动态扩展模块

11.32PHP动态扩展模块