10. PHP扩展模块安装

Posted

tags:

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

[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

[[email protected] phpredis-develop]# yum install -y autoconf

重新生成configure

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

技术分享图片

3. 编译配置:

[[email protected] 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这个插件!这就是我们需要的扩展模块

[[email protected] phpredis-develop]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[[email protected] 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

[[email protected] 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]

不支持,找到模块路径

[[email protected] phpredis-develop]# /usr/local/php7/bin/php -m |grep redis

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

[[email protected] 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.手动添加模块

[[email protected] phpredis-develop]# vim /usr/local/php7/etc/php.ini  

搜索 /extension
extension = redis.so

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

2.编译自带的PHP源码包

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

[[email protected] phpredis-develop]# cd /usr/local/src/php-7.1.6/
[[email protected] php-7.1.6]# cd ext/
[[email protected] 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包,

[[email protected] ext]# /usr/local/php7/bin/php -m |grep zip
[[email protected] ext]# cd zip/
[[email protected] 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目录。 然后输入:

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

3.make;make install

[[email protected] zip]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[[email protected] 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

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

Linux下单独编译安装PHP扩展包

PHP扩展模块安装

Laravel基本使用

PHP扩展模块安装

PHP动态扩展模块安装

88.PHP扩展模块安装