下載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 ]# wget http://pecl.php.net/get/redis-3.1.3.tgz
到了這一步,我們要使用安裝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服務器,重啓
service php-fpm restart
service nginx restart