php-redis安装笔记

 

redis源码下载:http://redis.io/download

php-redis源码下载:https://pecl.php.net/package/redis

  或:https://github.com/owlient/phpredis/tarball/master

 

解压redis源码 基本安装请见./README

 

cp redis.conf /etc  #复制配置文件

 

新建用户(可忽略)及创建相应文件夹:

sudo useradd redis
sudo mkdir -p /var/lib/redis
sudo mkdir -p /var/log/redis
sudo chown redis.redis /var/lib/redis #db文件放在这里,要修改redis.conf
sudo chown redis.redis /var/log/redis

 

服务脚本:

chmod +x /etc/init.d/redis

内容:

###########################
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
   
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
   
PIDFILE=/var/run/redis.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
        if [ "$?"="0" ] 
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
##############################

 

让redis以后台daemon的方式运行,需修改redis.conf:

将 daemonize no 改为 daemonize yes 

启动服务测试后结束redis安装

 

继续php-redis安装

 

解压php-redis源码后进入目录,

 

使用phpize建立php的外挂模块:

编译安装的php需要找到phpize路径在php-redis源码目录执行一下,例如:

/usr/local/php/bin/phpize 

如果yum之类的安装,centos需要php-devel,ubuntu需要php5-dev

也是在php-redis源码目录执行phpize命令

 

执行之后编译:

./configure --with-php-config=/usr/local/php/bin/php-config #phpinfo看下自己的php配置文件路径
make && make install #成功后注意查看so文件的存放目录

 

php.ini中添加配置:

extension=redis.so #注意路径

 

重启http服务软件,查看phpinfo,完毕。

 

 

End.

 

posted @ 2015-04-07 10:41  lianche  阅读(204)  评论(0编辑  收藏  举报