安装前
首先进行升级,要不然可能安装的是老的版本
yum -y update
查看是否已安装编译器
rpm -qa gcc
如果没有,则进行安装
yum install gcc gcc-c++
安装上传下载命令
yum install lrzsz
1、安装nginx
安装nginx依赖包
nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法:
yum -y install pcre pcre-devel
nginx的各种模块中需要使用gzip压缩:
yum -y install zlib zlib-devel
安全套接字层密码库:
yum -y install openssl openssl-devel
下载nginx文件
链接:https://pan.baidu.com/s/1DLZh8Kl9n5TofAeER7ok4A
提取码:hi5e
下载到电脑上,用rz命令进行

tar -zxvf nginx-1.12.2.tar.gz
编译安装(到/usr/local/nginx目录中)
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module
make
make install
创建并设置nginx运行账号:
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
设置user参数
vi nginx.conf

修改user 为nginx

设置nginx为系统服务
vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启动nginx
service nginx start
或者
systemctl start nginx.service
设置nginx开机自启动
systemctl enable nginx.service
检查开机自动是否设置成功
systemctl list-dependencies | grep nginx

创建conf.d目录

修改nginx.conf配置
log_format前面#去掉
增加include conf.d/*.conf;

创建目录,并赋予权限
mkdir -p /www/logs/nginx
chmod -R 777 /www/
在conf.d中添加配置文件test.conf
server {
listen 80;
server_name test.bj.local;
#charset koi8-r;
access_log /www/logs/nginx/$host.access.log main;
location /
CentOS7搭建PHP7.2+Nginx+MySQL5.7.21详述

本文详细介绍了如何在CentOS7系统上从零开始搭建PHP7.2、Nginx1.10.2和MySQL5.7.21的环境。包括升级系统、安装编译器、安装Nginx及其依赖、配置Nginx、安装PHP及其依赖、配置PHP-fpm、安装MySQL并初始化数据库、设置防火墙规则等步骤。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



