LNMP结合Redis实现会话共享

实验逻辑图如下

在这里插入图片描述

实验环境

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> 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值