Redis安装与PHP7.0扩展

原创
2018/03/15 11:04
阅读数 2K

操作系统:CentOS7.2 64位

一、安装Redis

1.下载最新版本:

$ wget http://download.redis.io/releases/redis-4.0.8.tar.gz
$ tar xzf redis-4.0.8.tar.gz
$ cp -p redis-4.0.8 /usr/local/redis4
$ cd redis4
$ make

这样就安装成功

2. 运行redis, 进入src目录,运行下面命令

$ src/redis-server

3. 测试:

$ src/redis-cli
redis> set hello world
OK
redis> get hello
"world"

4. 自启动

$ cp /usr/local/redis4/redis.conf /etc/redis.conf
$ vim /etc/redis.conf
编辑如下
daemonize yes

$ cp /usr/local/redis4/utils/redis_init_script /etc/rc.d/init.d/redis 
$ cd /etc/rc.d/init.d/
$ vim redis #把里面的运行目录换成你自己的,并加上chkconfig和description


#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database

REDISPORT=6379
EXEC=/usr/local/redis4/src/redis-server
CLIEXEC=/usr/local/redis4/src/redis-cli

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

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

自启动:

$ chkconfig redis on

$ service redis start  #启动
$ service redis stop   #关闭服务

二、安装Redis PHP扩展

1.下载安装扩展

$ wget http://pecl.php.net/get/redis-4.0.0RC2.tgz
$ tar zxvf redis-4.0.0RC2.tgz
$ cd redis-4.0.0RC2

$ /usr/local/php7/bin/phpize   ----给PHP动态添加扩展命令,在php的bin目录下
$ ./configure -with-php-config=/usr/local/php7/bin/php-config
$ make && make install

2.在php.ini里添加扩展名称

$ vim /usr/local/php7/etc/php.ini
extension=redis.so --添加扩展名称
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部