1、安装 LNMP 各个组件
2、安装Redis 服务
3、安装 Redis 扩展
1、安装 LNMP 各个组件,完成后测试一下
(1)查看一下服务是否开启
(2)验证 php 测试页,安装成功
2、安装Redis 服务
systemctl stop firewalld setenforce 0
cd /opt/
ls
yum install -y gcc gcc-c++ make tar zxvf redis-5.0.7.tar.gz -C /opt/ cd redis-5.0.7/ make make PREFIX=/usr/local/redis install cd utils/ ./install_server.sh 回车四次后,第五次需要手动输入 Please select the redis executable path [] /usr/local/redis/bin/redis-server
ln -s /usr/local/redis/bin/* /usr/local/bin/
/etc/init.d/redis_6379 start
netstat -natp | grep 6379
(1)传入软件包并解压
(2)编译并安装
(3)执行安装服务脚本
(4)启动redis服务
3、安装 Redis 扩展
下载包:
https://codeload.github.com/phpredis/phpredis/zip/develop
http://download.redis.io/releases/redis-3.2.5.tar.gz
cd /opt/ tar -zxvf redis-4.0.2.tgz cd /opt/redis-4.0.2 ls phpize #运行 phpize 脚本的用途是动态安装 php 扩展模块
/usr/local/php/bin/phpize
#开始编译安装
./configure --with-php-config=/usr/local/php/bin/php-config --enable-redis #指定扩展模块的配置文件,开启redis
make && make install
//Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
redis.so
(1)传入 redis 扩展包并解压
(2)运行 phpize 脚本,编译并安装
4、修改 php 配置文件
vim /usr/local/php/lib/php.ini extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/" #736行,指定redis模块目录 extension = "redis.so" #738行,修改参数项名称为extension,指定redis模块名称 systemctl restart php-fpm.service php -m | grep redis
5、测试连接
5、测试连接 cd /usr/local/nginx/html/ vim set.php <?php $redis = new redis(); $redis->connect(‘127.0.0.1‘, 6379); $redis->set(‘test‘,"1111111111"); echo $redis->get(‘test‘); ?> curl http://127.0.0.1/set.php vim get.php <?php $redis = new redis(); $redis->connect(‘127.0.0.1‘, 6379); $result = $redis->get(‘test‘); var_dump($result); ?> curl http://127.0.0.1/get.php //结果:string(10) "1111111111"