Redis 安装:
1.切换目录
cd /usr/local/src
2.下载
wget http://download.redis.io/releases/redis-5.0.9.tar.gz
3.解压:
tar xzf redis-5.0.9.tar.gz
4.移动路径
mv redis-5.0.9 /usr/local/redis
- 进入redis目录
cd /usr/local/redis
- 安装redis
sudo make && sudo make install
- 运行
[root@localhost redis]# src/redis-server
这个并不是在后台运行redis,所以当命令行界面关闭的时候,就会失去链接,所以为了方便,我们需要将他配置为后台运行,编辑配置文件:vim /usr/local/redis/redis.conf
。将daemonize=no改为daemonize=yes 然后保存。
再次启动,指定配置redis文件
root@localhost redis]# /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
这个时候我们的redis服务段就已经后台运行了。可以进去redis客户端进行测试,启动客户端:
/usr/local/redis/src/redis-cli
,get、set键值是否成功。
php安装redis扩展
1.切换目录
cd /usr/local/src
2.下载(地址:http://pecl.php.net/package/redis)
wget http://pecl.php.net/get/redis-5.0.0.tgz
3.解压
tar zxvf redis-5.0.0.tgz
4.进入php-redis目录
cd redis-5.0.0
5.执行phpize (根据自己的phpize路径来填写)
/usr/local/php/bin/phpize
6.指定php配置路径(根据自己的php路径来填写)
./configure --with-php-config=/usr/local/php/bin/php-config
7.编译安装
sudo make && sudo make install
在源码编译PHP-redis扩展时,遇到缺少头文件问题,
error: ext/standard/php_smart_str.h: No such file or directory
,原因:PHP安装好的头文件目录:/php/include/php/ext/standard/,这些头文件,在php7之前的版本,是包含 php_smart_str.h 的,但7版本中没有 ,而是 php_smart_string.h ,所以需要根据php的版本来下载不同的redis扩展包;
8.编译安装无报错后,将扩展加入php配置文件php.ini中 php.ini的路径是你自己环境的路径
/usr/local/php/etc/php.ini
[root@localhost src]# tail -f /usr/local/php/etc/php.ini
; attempt to use the OS-managed cert stores in its absence. If specified,
; this value may still be overridden on a per-stream basis via the "capath"
; SSL stream context option.
;openssl.capath=
; Local Variables:
; tab-width: 4
; End:
extension=redis.so
9.重启php,查看扩展时候有redis
[root@localhost phpredis-5.0.0]# cd /usr/local/src/
[root@localhost src]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost src]# php --ri redis
redis
Redis Support => enabled
Redis Version => 5.0.0
Available serializers => php, json
Directive => Local Value => Master Value
redis.arrays.algorithm => no value => no value
redis.arrays.auth => no value => no value
redis.arrays.autorehash => 0 => 0
redis.arrays.connecttimeout => 0 => 0
redis.arrays.distributor => no value => no value
redis.arrays.functions => no value => no value
redis.arrays.hosts => no value => no value
redis.arrays.index => 0 => 0
redis.arrays.lazyconnect => 0 => 0
redis.arrays.names => no value => no value
redis.arrays.pconnect => 0 => 0
redis.arrays.previous => no value => no value
redis.arrays.readtimeout => 0 => 0
redis.arrays.retryinterval => 0 => 0
redis.arrays.consistent => 0 => 0
redis.clusters.cache_slots => 0 => 0
redis.clusters.auth => no value => no value
redis.clusters.persistent => 0 => 0
redis.clusters.read_timeout => 0 => 0
redis.clusters.seeds => no value => no value
redis.clusters.timeout => 0 => 0
redis.pconnect.pooling_enabled => 1 => 1
redis.pconnect.connection_limit => 0 => 0
redis.session.locking_enabled => 0 => 0
redis.session.lock_expire => 0 => 0
redis.session.lock_retries => 10 => 10
redis.session.lock_wait_time => 2000 => 2000
网友评论