实验逻辑图如下
实验环境
LNMP服务器和Redis服务器均为centos6系统
实验之前均关闭防火墙和selinux
[root@localhost ~]# service iptables stop
[root@localhost ~]# setenforce 0
Redis服务器配置
Redis源码安装教程
链接 >> https://blog.csdn.net/m0_46674735/article/details/109823943
LNMP服务器配置
nginx安装
源码安装nginx
链接>> https://blog.csdn.net/m0_46674735/article/details/109709606
安装完成之后测试
PHP安装
安装电商所需php-gd
结合数据库所需php-mysql
结合 nginx所需php-fpm
结合Redis所需php-pecl-redis
[root@localhost ~]# yum -y install php php-gd php-mysql php-fpm php-pecl-redis
安装成功
MySQL安装配置
安装
[root@localhost nginx-1.18.0]# yum -y install mysql mysql-server
启动
[root@localhost nginx-1.18.0]# service mysqld start
创建电商数据库并授权
mysql> create database tinyshop charset utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on *.* to tinyshop@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)
nginx整合php配置
修改nginx配置文件
开启php-fpm并重启nginx
[root@localhost nginx]# service php-fpm start
Starting php-fpm: [ OK ]
[root@localhost nginx]# sbin/nginx -s reload
编写PHP测试页面
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# vim index.php
[root@localhost html]# cat index.php
<?php
phpinfo();
?>
访问php测试页面
php已经支持Redis
session保存方式和文件
修改php-fpm的配置文件
[root@localhost html]# vim /etc/php-fpm.d/www.conf
将配置文件的最后两行修改如下
保存退出后重启php-fpm
[root@localhost html]# service php-fpm restart
再次访问php测试页面
修改成功
上传电商包测试会话
[root@localhost html]# tar xf tinyshopV2.5_data.tar
[root@localhost html]# ls
50x.html data framework index.php license.txt protected static tinyshopV2.5_data.tar
cache favicon.ico index.html install logs runtime themes
修改权限
[root@localhost html]# chmod -R 777 .*
安装
登录
在Redis上验证会话已经保存
root@localhost ~]# !r
redis-cli
127.0.0.1:6379> keys *
1) "PHPREDIS_SESSION:8rrfm0be34mqjhkhl3g73g1sv1"
2) "name"
127.0.0.1:6379>