部署支持php和Redis的Nginx服务器
一.安装并配置Nginx服务器
- 在nginx1(192.168.1.10)上安装nginx
# 安装编译器
[root@nginx1 ~]# yum install -y gcc pcre-devel zlib-devel# 编译安装nginx
[root@nginx1 ~]# tar xf nginx-1.12.2.tar.gz
[root@nginx1 ~]# cd nginx-1.12.2
[root@nginx1 nginx-1.12.2]# ./configure
[root@nginx1 nginx-1.12.2]# make && make install
```- 安装php-fpm
[root@nginx1 ~]# yum install -y php-fpm
[root@nginx1 ~]# systemctl start php-fpm
[root@nginx1 ~]# ss -tlnp | grep :9000
LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=11310,fd=0),("php-fpm",pid=11309,fd=0),("php-fpm",pid=11308,fd=0),("php-fpm",pid=11307,fd=0),("php-fpm",pid=11306,fd=0),("php-fpm",pid=11305,fd=6))
```- 修改配置文件
[root@nginx1 ~]# vim +65 /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
```- 启动nginx服务
[root@nginx1 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@nginx1 ~]# /usr/local/nginx/sbin/nginx
[root@nginx1 ~]# ss -tlnp | grep :80
LISTEN 0 128 *:80 *:* users:(("nginx",pid=11376,fd=6),("nginx",pid=11375,fd=6))
```- 测试
[root@nginx1 ~]# vim /usr/local/nginx/html/test.php
<?php
echo "Hello World!\n";
phpinfo();
?>[root@nginx1 ~]# curl http://127.0.0.1/test.php
Hello World!
... ...
```
二.安装redis
[root@redis1 ~]# yum install -y gcc
[root@redis1 ~]# wget https://download.redis.io/releases/redis-4.0.8.tar.gz
[root@redis1 ~]# tar xf redis-4.0.8.tar.gz
[root@redis1 ~]# cd redis-4.0.8# 修改安装目录为/usr/local/redis
[root@redis1 redis-4.0.8]# vim +27 src/Makefile
PREFIX?=/usr/local/redis# 编译安装
[root@redis1 redis-4.0.8]# make && make install# 将redis命令目录添加至PATH环境变量
[root@redis1 redis-4.0.8]# vim /etc/bashrc # 尾部追加
export PATH=$PATH:/usr/local/redis/bin
[root@redis1 redis-4.0.8]# source /etc/bashrc# 初始化redis服务
[root@redis1 redis-4.0.8]# ./utils/install_server.sh # 全部问题直接回车采用默认值
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/redis/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/redis/bin/redis-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
三.配置PHP支持Redis
- 安装php扩展
[root@nginx1 ~]# yum install -y php-devel automake autoconf
```- 安装php-redis
下载地址
http://windows.php.net/downloads/pecl/snaps/redis/2.2.5/
[root@nginx1 ~]# tar xf redis-cluster-4.3.0.tgz
[root@nginx1 ~]# cd redis-4.3.0/
[root@nginx1 redis-4.3.0]# phpize
[root@nginx1 redis-4.3.0]# ./configure --with-php-config=/usr/bin/php-config
[root@nginx1 redis-4.3.0]# make && make install[root@nginx1 redis-4.3.0]# ls /usr/lib64/php/modules/redis.so
/usr/lib64/php/modules/redis.so- 修改php配置文件并重启服务
[root@nginx1 redis-4.3.0]# vim /etc/php.ini # 在730行下添加
extension_dir = "/usr/lib64/php/modules"
extension = "redis.so"[root@nginx1 ~]# systemctl restart php-fpm
```- 测试
# 创建脚本,写入redis数据库
[root@nginx1 ~]# vim /usr/local/nginx/html/set_redis.php<?php
$redis = new redis();
$redis->connect("192.168.1.11", "6379");
$redis->auth("tedu.cn");
$redis->set("username", "tom");
?># 创建脚本,读取redis数据
[root@nginx1 ~]# vim /usr/local/nginx/html/get_redis.php
<?php
$redis = new redis();
$redis->connect("192.168.1.11", "6379");
$redis->auth("tedu.cn");
echo $redis->get("username");
?># 访问测试页面
[root@nginx1 ~]# curl http://127.0.0.1/set_redis.php
[root@nginx1 ~]# curl http://127.0.0.1/get_redis.php
tom# 在redis数据库上查看
[root@redis1 ~]# redis-cli -a tedu.cn
127.0.0.1:6379> KEYS *
1) "username"
127.0.0.1:6379> GET username
"tom"
部署支持php和Redis的Nginx服务器相关推荐
- nginx部署两个php虚拟主机,nginx服务器,fastcgi模式,添加虚拟主机(多站点)配置...
phpStudy套件是一个非常火的php环境包,是一个非常不错的本地调试环境,支持xp.win7.win10,甚至很多朋友直接用在个人服务器上,虽然本人不推荐......但是这样确实很省事. 所以在欢 ...
- QUIC实战(五) 使用nginx quic开发分支部署支持HTTP3 的NGINX
使用nginx + Quiche 部署的支持HTTP3的nginx在实际测试过程中遇到了一些问题,Quiche本身是由go + rust编写的,nginx又是由c++编写的,对于我们来说未知的内容太多 ...
- Nginx服务器证书部署-亚洲诚信
Nginx服务器证书部署 发布时间:2018-01-17 16:15:25 依赖建议 l SSL卸载驱动.建议:openssl版本1.1.0f+. l nginx版本Stable version: ...
- 部署Nginx服务器
部署Nginx服务器 常见的web服务器: unix和linux平台下: --Apache.Nginx.Lighttpd. --Tomcat.IBM WebSphere windows平台下: --微 ...
- nginx【nginx跨域、nginx开启gizp压缩、nginx服务器部署项目】
nginx是一个高性能的HTTP和反向代理服务器,它使用配置文件决定如何提供内容.要监听的端口等.因此常用来做静态资源服务器和后端的反向代理服务器. 安装:brew install nginx 启动: ...
- 一文搞懂使用Nginx服务器部署前端Web项目
1 Nginx简介与安装 概要 Nginx 简介 Nginx 架构说明 Nginx 基础配置与使用 1.1 Nginx 简介 Nginx是一个高性能WEB服务器,除它之外Apache.Tomcat.J ...
- 国产银河麒麟系统部署Redis、Nginx分享
前提需知: 银河麒麟系统国产机不能解压安装,需要用rpm安装包.使用命令安装:npm -i. 常用命令: pm -q(query)软件包查询功能 例如:rpm -q jdk 或者 rpm -qa jd ...
- 部署支持使用Redis哨兵模式,支持纳管ClickHouse数据库,JumpServer堡垒机v2.28.0发布
2022年11月21日,JumpServer开源堡垒机正式发布v2.28.0版本.在这一版本中,JumpServer的部署支持使用Redis哨兵集群作为后端缓存数据库,从而使系统更加健壮和高可用.操作 ...
- Nginx服务器部署SSL证书
http://jingyan.baidu.com/article/154b463178eac928ca8f41a9.html SSL证书也称为服务器证书,是遵守全球统一的严格身份认证的SSL协议的一种 ...
最新文章
- HDU2553 N皇后问题
- 别为iptables日志付出太多-一种Linux防火墙优化方法
- Errors were encountered while processing 解决方法
- SAP UI5 应用开发教程之一:Hello World
- 【LeetCode】剑指 Offer 46. 把数字翻译成字符串
- 编写javascript、Jquery的String.format();
- 时间序列-N-CNN-LSTM
- 决策树 结构_如何快速简单的理解决策树的概念?
- 2,一个人体姿态识别的项目实现
- 汉语语句的计算机分析,(计算机专业毕业论文)汉语语法自动分析.doc
- 如何查询iPhone手机的序列号?苹果序列号查询方法
- 人民银行新闻发布会:详细解读2020年上半年金融统计数据
- SQL语法之分组函数,分组查询(进阶5)and连接查询(sql92语法进阶6)
- js实现倒计时,定时器--完成时间倒计时
- 2020.12.22 ps临摹调色
- 蚁视牵手联创互联,可持续拓展“第六媒体”新业态
- 遇到jQuery 中的 slideUp ,slideToggle和 slideDown 动画重复执行
- java quartz 动态执行,浅谈SpringBoot集成Quartz动态定时任务
- 【Doris Weekly FAQ】2021.07.05~2021.07.18
- 如何在ZBrush中将球体演变为头发
热门文章
- iOSCoreAnimation动画系列教程(一):CABasicAnimation【包会】
- ROS探索总结(十六)(十七)(十八)(十九)——HRMRP机器人的设计 构建完整的机器人应用系统 重读tf 如何配置机器人的导航功能
- OpenCV之feature2d 模块. 2D特征框架(2)特征描述 使用FLANN进行特征点匹配 使用二维特征点(Features2D)和单映射(Homography)寻找已知物体 平面物体检测
- 撰写英文SCI文章的技巧
- 程序员面试题精选100题(50)-树的子结构[数据结构]
- 使用docker安装部署Spark集群来训练CNN(含Python实例)
- 图像处理与计算机视觉:基础,经典以及最近发展(3)计算机视觉中的信号处理与模式识别
- spring注入出错
- [洛谷1390]公约数的和
- 带你认识“货真价实”的P2P网贷风控