centos7 php开发环境安装-Redis
1.安装依赖包
yum install gcc-c++
2.redis安装
wget http://download.redis.io/releases/redis-5.0.7.tar.gz tar xzf redis-5.0.7.tar.gz cd redis-5.0.7 make make install PREFIX=/usr/local/redis
make install 加上需要安装的redis目录地址
3.配置与启动
1.拷贝配置文件 cp -r redis.conf /usr/local/redis/bin/ 2.开启服务端 ./redis-server redis.conf
4.客户端连接redis
cd /usr/local/redis/ ./redis-cli -h 127.0.0.1 -p 6379
5.环境变量
1. 打开bash_profile配置 vim ~/.bash_profile 2.文件中添加: export REDIS_HOME=/usr/local/redis export PATH=$PATH:$REDIS_HOME/bin 3.重启 source ~/.bash_profile
6.设置后台运行
vim redis.conf
daemonize no修改为daemonize yes即可
重启redis:
ps -ef|grep redis
kill -9 20940
./redis-server redis.conf
7开机启动
7.1.创建文件 vim /etc/init.d/redis
7.2.编辑内容添加:
#!/bin/bash #chkconfig: 22345 10 90 #description: Start and Stop redis REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli PIDFILE=/var/run/redis.pid CONF="/usr/local/redis/bin/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 ;; restart) "$0" stop sleep 3 "$0" start ;; *) echo "Please use start or stop or restart as first argument" ;; esac
7.3 权限及开机启动
chmod +x /etc/init.d/redis #chkconfig --add redis #chkconfig redis on #chkconfig --list //查看所有注册的脚本文件
8.phpredis 配置
1.下载 wget https://pecl.php.net/get/redis-5.0.0.tgz 2.解压 tar -zxvf redis-5.0.0.tgz 3.进入目录 cd redis-5.0.0 4.phpize /usr/local/php/bin/phpize 5.configure ./configure --with-php-config=/usr/local/php/bin/php-config 6.安装 make make install 7.php配置文件编辑添加 Php.ini 增加extension="redis.so" 8.重启服务环境apache或Nginx 9.Phpinfo 验证 打印页面,查看是否有redis扩展信息 10.Php代码验证 编写php代码连接reids并操作 11.注意端口是否已经开放