[toc]

PHP扩展模块安装

下载安装redis

redis 在LAMP下,被当作缓存来使用!

1. 下载并切换到指定目录:

cd /usr/local/src/
wget https://codeload.github.com/phpredis/phpredis/zip/develop 
mv develop phpredis-develop.zip     //改名
unzip phpredis-develop.zip  //解压缩
cd phpredis-develop

2. 生成configure:

/usr/local/php7/bin/phpize   //生成configure文件

有时候安装会出错,缺少一个包autoconf

[root@xavi phpredis-develop]# yum install -y autoconf

重新生成configure

[root@xavi phpredis-develop]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

mark

3. 编译配置:

[root@xavi phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config

4. 安装测试:

make

make install

ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so  redis.so

然后就会有redis.so这个插件!这就是我们需要的扩展模块

[root@xavi phpredis-develop]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[root@xavi phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so  redis.so

5. 查看php是否支持redis:/usr/local/php7/bin/php -m |grep redis

[root@xavi phpredis-develop]# /usr/local/php7/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
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]

不支持,找到模块路径

[root@xavi phpredis-develop]# /usr/local/php7/bin/php -m |grep redis

6.查找extension_dir,查看扩展模块存放目录,我们可以在php.ini中去自定义该路径

[root@xavi phpredis-develop]# /usr/local/php7/bin/php -i |grep extension_dir 
extension_dir => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303
sqlite3.extension_dir => no value => no value

7.手动添加模块

[root@xavi phpredis-develop]# vim /usr/local/php7/etc/php.ini  

搜索 /extension
extension = redis.so

[root@xavi phpredis-develop]# vim /usr/local/php7/etc/php.ini  
[root@xavi phpredis-develop]# /usr/local/php7/bin/php -m |grep redis
redis

2.编译自带的PHP源码包

实际上在php7的源码包中,有很多自带的源码包。我们不需要再次下载,直接编译即可!

[root@xavi phpredis-develop]# cd /usr/local/src/php-7.1.6/
[root@xavi php-7.1.6]# cd ext/
[root@xavi ext]# ls
bcmath              fileinfo   libxml     pdo_firebird  session    tidy
bz2                 filter     mbstring   pdo_mysql     shmop      tokenizer
calendar            ftp        mcrypt     pdo_oci       simplexml  wddx
com_dotnet          gd         mysqli     pdo_odbc      skeleton   xml
ctype               gettext    mysqlnd    pdo_pgsql     snmp       xmlreader
curl                gmp        oci8       pdo_sqlite    soap       xmlrpc
date                hash       odbc       pgsql         sockets    xmlwriter
dba                 iconv      opcache    phar          spl        xsl
dom                 imap       openssl    posix         sqlite3    zip
enchant             interbase  pcntl      pspell        standard   zlib
exif                intl       pcre       readline      sysvmsg
ext_skel            json       pdo        recode        sysvsem
ext_skel_win32.php  ldap       pdo_dblib  reflection    sysvshm

然后我们会发现有很多自带的源码包,

1. 首先我们先确认一个zip包,

[root@xavi ext]# /usr/local/php7/bin/php -m |grep zip
[root@xavi ext]# cd zip/
[root@xavi zip]# ls
config.m4   CREDITS   lib             php_zip.c  tests  zip_stream.c
config.w32  examples  LICENSE_libzip  php_zip.h  TODO

2.假如我们需要编译一个zip,首先进入zip目录。 然后输入:

[root@xavi zip]# /usr/local/php7/bin/phpize 
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
[root@xavi zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config

3.make;make install

[root@xavi zip]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[root@xavi zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so  redis.so  zip.so

部分转载来源:PHP扩展模块安装 - Laoqi's Blog

实用扩展:

apache rewrite教程 http://coffeelet.blog.163.com/blog/static/13515745320115842755199/

http://www.cnblogs.com/top5/archive/2009/08/12/1544098.html

apache rewrite 出现死循环 http://ask.apelearn.com/question/1043

php错误日志级别参考 http://ask.apelearn.com/question/6973

php开启短标签 http://ask.apelearn.com/question/120

php.ini详解 http://legolas.blog.51cto.com/2682485/493917