溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

在centos7中怎么為php7安裝redis擴(kuò)展

發(fā)布時(shí)間:2021-05-19 09:40:21 來源:億速云 閱讀:196 作者:小新 欄目:編程語言

這篇文章主要介紹在centos7中怎么為php7安裝redis擴(kuò)展,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

下載redis

下載redis,解壓,編譯:

$ wget http://download.redis.io/releases/redis-4.0.6.tar.gz
$ tar xzf redis-4.0.6.tar.gz
$ cd redis-4.0.6
$ make && make PREFIX=/usr/local/redis install  #安裝到指定目錄

現(xiàn)在去剛剛tar包解壓出來的源碼目錄中,拷貝一個(gè)redis.conf配置文件,放到/usr/local/redis/bin/目錄下

進(jìn)入到redis目錄下,運(yùn)行vi redis.conf

將daemonize no改為 daemonize yes保存退出

通過下面的命令啟動(dòng)Redis服務(wù):

./bin/redis-server ./redis.conf

在centos7中怎么為php7安裝redis擴(kuò)展

你可以使用內(nèi)置的客戶端命令redis-cli進(jìn)行使用:

$ ./redis-cli
redis> set foo bar
OK
redis> get foo"bar"

以上呢是安裝redis程序

在php7中要開啟redis擴(kuò)展

使用git clone下載git上的phpredis擴(kuò)展包

[root@localhost local ]#git clone  https://github.com/phpredis/phpredis.git

到了這一步,我們要使用安裝php時(shí)生成的phpize來生成configure配置文件,

//具體用哪個(gè)要取決于你的phpize文件所在的目錄,這時(shí)你應(yīng)該用 whereis phpize 來查看路徑

[root@localhost local ]# whereis phpize
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz

這里表明路徑為/usr/bin/phpize,然后執(zhí)行:

[root@localhost phpredis ]# /usr/bin/phpize
Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.

這里報(bào)錯(cuò)了,原因是沒有安裝好php-devel,由于我是使用的php7.0所以執(zhí)行以下命令:

[root@localhost phpredis]#yum -y install php70w-devel

然后再次執(zhí)行:

[root@localhost phpredis]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012

執(zhí)行完上一步,我們就有了 configure 配置文件了,接下來配置

[root@localhost phpredis]#./configure

或者執(zhí)行

[root@localhost phpredis]#./configure --with-php-config=/usr/bin/php-config

接下來是編譯安裝

[root@localhost phpredis]#make 
[root@localhost phpredis]# make install
 Installing shared extensions:      /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/

配置php的配置文件php.ini(具體放在那里可以用 whereis php.ini 來查看),我的配置文件php.ini在/etc/下

[root@localhost phpredis]#vim /etc/php.ini

開啟redis擴(kuò)展:

extension = redis.so

redis.so文件的路徑可以在make install的時(shí)候看到

[root@localhost local]# php -m  #查詢php的擴(kuò)展

在centos7中怎么為php7安裝redis擴(kuò)展

重啟nginx服務(wù)器,重啟php-fpm,使配置生效

重啟之后我們打開info.php,已經(jīng)可以看到redis的擴(kuò)展信息了

在centos7中怎么為php7安裝redis擴(kuò)展

以上是“在centos7中怎么為php7安裝redis擴(kuò)展”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI