前言
- LAMP 中的“A”对应着Web服务器软件 Apache HTTP server
- 随着 Nginx 在企业中的使用越来越多,LNMP 架构也就受到越来越多 Linux 系统工程师的青睐,其中的“N”对应着 Nginx 服务
- 就像构建 LAMP 平台一样,构建 LNMP 平台也需要 Linux 服务器、MySQL 数据库 和 PHP 解析环境,区别主要在 Nginx 和 PHP 的协作配置上
- 本文环境基于 CentOS 7,已装好本地 YUM 源仓库
一、安装 Nginx 服务
这里我之前的文章有讲述,在此仅贴出相关配置步骤的代码,不做复述
传送门(文章内有软件包下载链接):
LAMP
Nginx
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
yum remove -y httpd
#之前若安装过,这里必须先卸载,会有冲突,本文使用源码编译安装
- 安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
- 创建运行用户
useradd -M -s /sbin/nologin nginx
- 编译安装
cd /opt
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make -j 2
make install
- 优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
- 添加 Nginx 系统服务
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=£orking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/ki11 -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
二、安装 MySQL 服务
- 安装 MySQL 环境依赖包