溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

在centos7中怎么為php7安裝redis擴展

發布時間:2021-05-19 09:40:21 來源:億速云 閱讀:250 作者:小新 欄目:編程語言

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

下載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  #安裝到指定目錄

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

進入到redis目錄下,運行vi redis.conf

將daemonize no改為 daemonize yes保存退出

通過下面的命令啟動Redis服務:

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

在centos7中怎么為php7安裝redis擴展

你可以使用內置的客戶端命令redis-cli進行使用:

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

以上呢是安裝redis程序

在php7中要開啟redis擴展

使用git clone下載git上的phpredis擴展包

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

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

//具體用哪個要取決于你的phpize文件所在的目錄,這時你應該用 whereis phpize 來查看路徑

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

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

[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.

這里報錯了,原因是沒有安裝好php-devel,由于我是使用的php7.0所以執行以下命令:

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

然后再次執行:

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

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

[root@localhost phpredis]#./configure

或者執行

[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擴展:

extension = redis.so

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

[root@localhost local]# php -m  #查詢php的擴展

在centos7中怎么為php7安裝redis擴展

重啟nginx服務器,重啟php-fpm,使配置生效

重啟之后我們打開info.php,已經可以看到redis的擴展信息了

在centos7中怎么為php7安裝redis擴展

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女