php-redis安裝筆記

 

redis源碼下載:http://redis.io/downloadphp

php-redis源碼下載:https://pecl.php.net/package/redisgit

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

 

解壓redis源碼 基本安裝請見./READMEredis

 

cp redis.conf /etc  #複製配置文件

 

新建用戶(可忽略)及建立相應文件夾:ubuntu

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

 

服務腳本:centos

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:spa

將 daemonize no 改成 daemonize yes .net

啓動服務測試後結束redis安裝rest

 

繼續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.

相關文章
相關標籤/搜索