linux 学习笔记-045-安装 PHP 扩展模块

发布于 2018-03-08  353 次阅读


安装 PHP 扩展模块

在日常使用的过程中,发现少了一个扩展模块,这时就需要安装扩展模块了

这里以安装 redis 模块为例:

[root@am-01:~#] cd /usr/local/src/

[root@am-01:/usr/local/src#] wget https://codeload.github.com/phpredis/phpredis/zip/develop

--2018-03-08 22:24:42--  https://codeload.github.com/phpredis/phpredis/zip/develop

正在解析主机 codeload.github.com (codeload.github.com)... 192.30.255.121, 192.30.255.120

正在连接 codeload.github.com (codeload.github.com)|192.30.255.121|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:230093 (225K) [application/zip]

正在保存至: “develop”



100%[====================================================================>] 230,093      108KB/s 用时 2.1s   



2018-03-08 22:24:50 (108 KB/s) - 已保存 “develop” [230093/230093])

[root@am-01:/usr/local/src#] mv develop phpredis-develop.zip

[root@am-01:/usr/local/src#] unzip phpredis-develop.zip

Archive:  phpredis-develop.zip

fd93e26fc42ae0be6c5d5510516933e7d9350722

   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/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/make-cluster.sh  

  inflating: phpredis-develop/tests/mkring.sh  

[root@am-01:/usr/local/src#] cd phpredis-develop/

[root@am-01:/usr/local/src/phpredis-develop#] /usr/local/php7/bin/phpize

Configuring for:

PHP Api Version:         20160303

Zend Module Api No:      20160303

Zend Extension Api No:   320160303

Cannot find autoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script.

#这句是使用 php7 自带的工具生成 configure 文件,这里提示缺少 autoconf 包,下面使用 yum 安装一下
[root@am-01:/usr/local/src/phpredis-develop#] yum -y install autoconf

已加载插件:fastestmirror

base                                                                                   | 3.6 kB  00:00:00     

epel/x86_64/metalink                                                                   | 6.7 kB  00:00:00     

epel                                                                                   | 4.7 kB  00:00:00     

extras                                                                                 | 3.4 kB  00:00:00     

updates                                                                                | 3.4 kB  00:00:00     

………………省略部分输出信息………………

已安装:

  autoconf.noarch 0:2.69-11.el7                                                                               



作为依赖被安装:

  m4.x86_64 0:1.4.16-10.el7                                                                                   



完毕!

[root@am-01:/usr/local/src/phpredis-develop#] /usr/local/php7/bin/phpize

Configuring for:

PHP Api Version:         20160303

Zend Module Api No:      20160303

Zend Extension Api No:   320160303

#可见再次生成 configure 文件的时候没有其他提示
[root@am-01:/usr/local/src/phpredis-develop#] ls

acinclude.m4      config.guess      CREDITS      Makefile.global      redis_array.h      redis_session.h      aclocal.m4      config.h.in      debian      missing      redis_array_impl.c      rpm      arrays.markdown    config.m4      debian.control      mkdeb-apache2.sh      redis_array_impl.h      run-tests.php      autom4te.cache      config.sub      install-sh      mkdeb.sh      redis.c      serialize.list      build      configure      ISSUE_TEMPLATE.md      mkinstalldirs      redis_cluster.c      tests      cluster_library.c      configure.in      liblzf      package.xml      redis_cluster.h      cluster_library.h      config.w32      library.c      php_redis.h      redis_commands.c      cluster.markdown      COPYING      library.h      README.markdown      redis_commands.h      common.h      crc16.h      ltmain.sh      redis_array.c      redis_session.c

#这是可以见到 configure 文件已经被生成
[root@am-01:/usr/local/src/phpredis-develop#] ./configure --with-php-config=/usr/local/php7/bin/php-config

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -E

checking for a sed that does not truncate output... /usr/bin/sed

checking for cc... cc

………………省略部分输出信息………………

creating libtool

appending configuration tag "CXX" to libtool

configure: creating ./config.status

config.status: creating config.h

[root@am-01:/usr/local/src/phpredis-develop#] make

[root@am-01:/usr/local/src/phpredis-develop#] make install

[root@am-01:/usr/local/src/phpredis-develop#] ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/

opcache.so  redis.so

#编译并安装,可见编译安装完之后会在 php7 目录下生成 redis.so 文件
[root@am-01:/usr/local/src/phpredis-develop#] /usr/local/php7/bin/php -m | grep redis

#现在并没有加载 redis 模块
[root@am-01:/usr/local/src/phpredis-develop#] /usr/local/php7/bin/php -i | grep -i 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

#查找扩展模块存放目录,这个目录是可以在 php.ini 中自定义的
[root@am-01:/usr/local/src/phpredis-develop#] vim /usr/local/php7/etc/php.ini

  extension=redis.so

[root@am-01:/usr/local/src/phpredis-develop#] /usr/local/php7/bin/php -m | grep redis

redis

#在 php 配置文件中添加一句(可以放到最后一行),启用 redis 模块,检查一下可见到已经加载 redis 模块

扩展

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