php扩展模块安装

6月4日任务

11.32 php扩展模块安装
扩展
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

 

11.32 php扩展模块安装

Redis模块的安装,首先wget下载源码包。

[root@jimmylinux-002 ~]# cd /usr/local/src
[root@jimmylinux-002 src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop 
--2018-06-03 12:38:49--  https://codeload.github.com/phpredis/phpredis/zip/develop
正在解析主机 codeload.github.com (codeload.github.com)... 54.251.140.56, 13.250.162.133, 13.229.189.0
正在连接 codeload.github.com (codeload.github.com)|54.251.140.56|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:238339 (233K) [application/zip]
正在保存至: “develop”

100%[=========================================================================>] 238,339     42.1KB/s 用时 5.5s   

2018-06-03 12:39:00 (42.1 KB/s) - 已保存 “develop” [238339/238339])

[root@jimmylinux-002 src]# ls
apr-1.5.2              httpd-2.4.33                                  php-5.6.30.tar.gz
apr-1.5.2.tar.gz       httpd-2.4.33.tar.gz                           php-7.1.6
apr-util-1.5.4         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz  php-7.1.6.tar.bz2
apr-util-1.5.4.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
develop                php-5.6.30

改名并解压

[root@jimmylinux-002 src]# mv develop phpredis-develop.zip
[root@jimmylinux-002 src]# unzip phpredis-develop.zip
Archive:  phpredis-develop.zip
28ec432247f597216846593d62b21e2eef8461c5
   creating: phpredis-develop/
  inflating: phpredis-develop/.gitignore  
  inflating: phpredis-develop/.gitmodules  
  inflating: phpredis-develop/.travis.yml  
  inflating: phpredis-develop/COPYING  
  inflating: phpredis-develop/CREDITS  
  inflating: phpredis-develop/INSTALL.markdown  
  inflating: phpredis-develop/ISSUE_TEMPLATE.md  
  inflating: phpredis-develop/README.markdown  
  inflating: phpredis-develop/arrays.markdown  
  inflating: phpredis-develop/cluster.markdown  
  inflating: phpredis-develop/cluster_library.c  
  inflating: phpredis-develop/cluster_library.h  
  inflating: phpredis-develop/common.h  
  inflating: phpredis-develop/config.m4  
  inflating: phpredis-develop/config.w32  
  inflating: phpredis-develop/crc16.h  
  inflating: phpredis-develop/debian.control  
   creating: phpredis-develop/debian/
  inflating: phpredis-develop/debian/changelog  
 extracting: phpredis-develop/debian/compat  
  inflating: phpredis-develop/debian/control  
  inflating: phpredis-develop/debian/copyright  
  inflating: phpredis-develop/debian/postinst  
  inflating: phpredis-develop/debian/postrm  
  inflating: phpredis-develop/debian/rules  
   creating: phpredis-develop/liblzf/
  inflating: phpredis-develop/library.c  
  inflating: phpredis-develop/library.h  
  inflating: phpredis-develop/mkdeb-apache2.sh  
  inflating: phpredis-develop/mkdeb.sh  
  inflating: phpredis-develop/package.xml  
  inflating: phpredis-develop/php_redis.h  
  inflating: phpredis-develop/redis.c  
  inflating: phpredis-develop/redis_array.c  
  inflating: phpredis-develop/redis_array.h  
  inflating: phpredis-develop/redis_array_impl.c  
  inflating: phpredis-develop/redis_array_impl.h  
  inflating: phpredis-develop/redis_cluster.c  
  inflating: phpredis-develop/redis_cluster.h  
  inflating: phpredis-develop/redis_commands.c  
  inflating: phpredis-develop/redis_commands.h  
  inflating: phpredis-develop/redis_session.c  
  inflating: phpredis-develop/redis_session.h  
   creating: phpredis-develop/rpm/
  inflating: phpredis-develop/rpm/php-redis.spec  
 extracting: phpredis-develop/rpm/redis.ini  
  inflating: phpredis-develop/serialize.list  
   creating: phpredis-develop/tests/
  inflating: phpredis-develop/tests/RedisArrayTest.php  
  inflating: phpredis-develop/tests/RedisClusterTest.php  
  inflating: phpredis-develop/tests/RedisTest.php  
  inflating: phpredis-develop/tests/TestRedis.php  
  inflating: phpredis-develop/tests/TestSuite.php  
  inflating: phpredis-develop/tests/getSessionData.php  
  inflating: phpredis-develop/tests/make-cluster.sh  
  inflating: phpredis-develop/tests/mkring.sh  
  inflating: phpredis-develop/tests/regenerateSessionId.php  
  inflating: phpredis-develop/tests/startSession.php 

因为缺少configure文件,没办法直接./方式编译,所以需要先生成configure文件。

[root@jimmylinux-002 src]# cd phpredis-develop
[root@jimmylinux-002 phpredis-develop]# /usr/local/php7/bin/phpize 
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  这里有报错,提示没有找到autoconf。
$PHP_AUTOCONF environment variable. Then, rerun this script.
[root@jimmylinux-002 phpredis-develop]# yum install -y autoconf  yum安装缺少的文件

安装完缺少的文件后再执行 /usr/local/php7/bin/phpize 生成configure

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

使用./进行配置

[root@jimmylinux-002 phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config
看到下面的提示说明配置完成
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

[root@jimmylinux-002 phpredis-develop]# echo $?  也可以使用echo命令检查,如果是0说明没有问题。
0

make命令开始编译

[root@jimmylinux-002 phpredis-develop]# make
看到下面提示说明编译完成
Build complete.
Don't forget to run 'make test'.

执行命令make install

[root@jimmylinux-002 phpredis-develop]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/  会把redis.so文件放到这个路径下

[root@jimmylinux-002 phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so  redis.so  这个目录就生成了一个redis.so,这个文件就是我们要的扩展模块。
[root@jimmylinux-002 phpredis-develop]# /usr/local/php7/bin/php -m  查看php支持的模块
[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]  现在php还不支持redis这个模块

[root@jimmylinux-002 phpredis-develop]# /usr/local/php7/bin/php -m |grep redis  这里也是没有加载出redis模块的
[root@jimmylinux-002 phpredis-develop]# 

需要编辑配置文件,让php支持redis这个模块。首先查看扩展模块存放目录,我们可以在php.ini中去自定义该路径

[root@jimmylinux-002 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  其实这个路径就是刚才生成redis模块的路径,一般保持默认路径不需要修改。
[root@jimmylinux-002 phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303
opcache.so  redis.so

编辑php.ini文件,增加一行配置,放到extension文件最后一行。

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

在extension中添加一行 extension=redis.so

;extension=php_pdo_firebird.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
extension=redis.so

这个时候再去查看就有加载redis模块了

 

总结:

扩展模块安装首先需要下载源码包,redis模块属于第三方提供,在PHP源码包里面本身是没有的,实际上PHP源码包的ext目录,里面有很多的模块,如果编译的模块已经在自带的源码包ext目录存在,那么可以直接进入到需要安装模块的目录,然后使用命令 /usr/local/php7/bin/phpize 编译,不需要再去下载了。

 

例如安装zip模块 

进入到ext目录可以看到很多PHP源码包自带的扩展模块

按照如下步骤操作:

[root@jimmylinux-002 zip]# cd zip

[root@jimmylinux-002 zip]# /usr/local/php7/bin/phpize

[root@jimmylinux-002 zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config

[root@jimmylinux-002 zip]# make

[root@jimmylinux-002 zip]# make install

[root@jimmylinux-002 zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so  redis.so  zip.so  这里就多了一个zip.so 模块

最后一步在php.ini配置文件添加extension=zip.so

[root@jimmylinux-002 zip]# vim /usr/local/php7/etc/php.ini

;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
extension=redis.so
extension=zip.so  配置文件中添加extension=zip.so

已经有zip说明安装成功

 

posted @ 2018-06-03 01:07  吉米乐享驿站  阅读(318)  评论(0编辑  收藏  举报