centos6安装redis和php扩展redis.so

每次都忘,记录一下,这里只记录普通环境

1、安装redis

下载地址:https://redis.io/download

这里直接复制官方的安装步骤,如下:

$ wget http://download.redis.io/releases/redis-4.0.11.tar.gz
$ tar xzf redis-4.0.11.tar.gz
$ cd redis-4.0.11
$ make
$ ln -s src/redis-server /usr/local/bin/redis-server

 然后接下来添加开机自启动

$ cp redis.conf /etc/
$ vi /etc/init.d/redis

#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/bin"
CONFIG="/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
        if [ -e $PIDFILE ];then
             echo "$desc already running...."
             exit 1
        fi
        echo -n $"Starting $desc: "
        daemon $BIN/$prog $CONFIG
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
        echo -n $"Stop $desc: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}
restart() {
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL

$ chmod 755 /etc/init.d/redis
$ vi /etc/redis.conf
#搜索 daemonize 值从no改为yes
$ /etc/init.d/redis start
$ chkconfig redis on 

 

2、安装php-redis扩展

$ wget https://github.com/phpredis/phpredis/archive/4.0.2.tar.gz
$ tar xzvf 4.0.2.tar.gz
$ cd phpredis-4.0.2/
#找到phpize路径和php-config路径
$ find / -name phpize
/www/server/php/70/bin/phpize
$ find / -name php-config
/www/server/php/70/bin/php-config
#编译
$ /www/server/php/70/bin/phpize
$ ./configure --with-php-config=/www/server/php/70/bin/php-config
$ make && make install
#找到php.ini路径,添加扩展
$ find / -name php.ini
/www/server/php/70/etc/php.ini

$ vi /www/server/php/70/etc/php.ini
extension = redis.so
#这里可以用make install 完成后的绝对路径

重启php-fpm,phpinfo()看一下有没有扩展信息

建个php文件测试下效果吧

connect('127.0.0.1',6379);
$redis->setex('test',60,'value');
echo $redis->get('test');

 

你可能感兴趣的:(Linux,php)