真正优秀的程序员是那些专注于认识、理解、沟通和解决问题的人,你得明白,软件只是用来增加效率的工具而已

centos6.8安装Redis和php扩展

一、编译安装Redis

1.下载安装Redis

wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar -zxvf redis-4.0.9.tar.gz
cd redis-4.0.9
make PREFIX=/usr/local/redis install

2.配置redis.conf

mkdir /usr/local/redis/etc/
cp redis.conf  /usr/local/redis/etc/ #当前还在安装目录中
cd /usr/local/redis/etc/
vim redis.conf
//编辑参数
daemonize yes  后台启动
pidfile /var/run/redis/redis_6379.pid
logfile "/var/log/redis/redis.log"

3.配置redis的服务脚本

  • 创建相关日志目录
useradd -r -s /sbin/nologin -M redis #创建启动脚本的用户
mkdir /var/run/redis
mkdir /var/log/redis
chown redis:redis /var/run/redis 
chown redis:redis /var/log/redis
  • 编辑redis启动脚本,把原脚本中的内容修改为如下内容
vi /etc/init.d/redis

#!/bin/sh
#chkconfig: 2345 10 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
BASEDIR=/usr/local/redis
EXEC=$BASEDIR/bin/redis-server
CLIEXEC=$BASEDIR/bin/redis-cli

PIDFILE=/var/run/redis/redis_${REDISPORT}.pid
CONF="$BASEDIR/etc/redis.conf"

4.设置redis 开机启动

chkconfig --add redis
chkconfig redis on   开启开机启动
打开redis命令:service redis start
关闭redis命令:service redis stop

查看redis 进程 ps -ef | grep -i redis

二、安装php redis

1.下载redis扩展并安装

cd /usr/local/src/
wget https://pecl.php.net/get/redis-4.0.0.tgz
tar -zxvf redis-4.0.0.tgz
cd redis-4.0.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install 

安装输出 Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/ 证明安装成功

2.配置redis扩展

cd /usr/local/php/etc/
echo "extension=redis.so" >> php.ini
service php-fpm restart #重启php 或者/etc/init.d/php-fpm restart

3.php中查看并测试

phpinfo(); # 会显示redis模块
$redis = new Redis();
echo ($redis-> pconnect('127.0.0.1',6379) ? "redis is connect\n" : "redis connect fail\n");

$redis->set('name','zhangwei');
echo $redis->get('name');

微风小站 » centos6.8安装Redis和php扩展
分享到: 更多 (0)