首頁  >  文章  >  後端開發  >  在centos7中如何為php7安裝redis擴充

在centos7中如何為php7安裝redis擴充

醉折花枝作酒筹
醉折花枝作酒筹轉載
2021-05-19 09:24:592122瀏覽

這篇文章要為大家介紹在centos7中為php7安裝redis擴充的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有幫助。

在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

#你可以使用內建的客戶端指令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的擴充功能


##重啟nginx伺服器,重啟php-fpm,讓設定生效

重啟之後我們打開info.php,已經可以看到redis的擴充資訊了

##推薦學習:

php影片教學

以上是在centos7中如何為php7安裝redis擴充的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除