步骤目录:
步骤一:LNMP 简介
步骤二:系统环境要求
步骤三:搭建 LNMP
3.1 Nginx 网页服务
3.1.1 安装 Nginx 网页服务
3.1.2 配置 Nginx 网页服务的配置文件
3.1.2.1 删除原有的 Nginx 网页服务的配置文件
3.1.2.2 创建新的 Nginx 网页服务的配置文件
3.1.2.3 配置 Nginx 网页服务的配置文件
3.1.3 启动 nginx 网页服务
3.2 MariaDB 数据库
3.2.1 安装 MariaDB 数据库
3.2.2 启动 MariaDB 数据库
3.3 PHP 环境和连接服务
3.3.1 安装 PHP 环境和连接服务
3.3.2 创建提供 php 连接服务的用户
3.3.3 配置 PHP 连接服务的配置文件
3.3.4 启动 PHP 连接服务
步骤四:后续工作
步骤五:测试 LNMP 平台
具体的操作步骤:
步骤一:LNMP 简介
LNMP 是一个实现网站服务的方法,它由 4 样东西组成:
1) Linux 系统
2) Nginx 网页服务
3) MariaDB 数据库
4) PHP 网页程序
步骤二:系统环境要求
1) 服务器的系统需要是 CentOS Linux 8 版本
2) 服务器要关闭防火墙
3) 服务器要关闭 SELinux
4) 服务器系统要配置好可用的软件源
步骤三:搭建 LNMP
3.1 Nginx 网页服务
3.1.1 安装 Nginx 网页服务
# yum -y install nginx
3.1.2 配置 Nginx 网页服务的配置文件
3.1.2.1 删除原有的 Nginx 服务的配置文件
# rm /etc/nginx/nginx.conf
3.1.2.2 创建新的 Nginx 网页服务的配置文件
# cp /etc/nginx/nginx.conf.default /etc/nginx.conf
3.1.2.3 配置 Nginx 网页服务的配置文件
# vi /etc/nginx/nginx.conf
将其中的:
......
location / {
root html;
index index.html index.htm;
}
......
#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_params;
#}
......
修改为:
......
location / {
root html;
index index.php index.html index.htm;
}
......
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 将对于 PHP 的请求传递到本机的 9000 端口为例)
3.1.3 启动 nginx 网页服务
# systemctl start nginx
3.2 MariaDB 数据库
3.2.1 安装 MariaDB 数据库
# yum -y install mariadb mariadb-server
3.2.2 启动 MariaDB 数据库
# systemctl start mariadb
3.3 PHP 环境和连接服务
3.3.1 安装 PHP 环境和连接服务
# yum -y install php php-fpm php-mysqlnd php-gd php-mbstring php-opcache php-json php-xml
3.3.2 创建提供 PHP 连接服务的用户
# useradd php-fpm -s /sbin/nologin
3.3.3 配置 PHP 连接服务的配置文件
# vi /etc/php-fpm.conf
添加以下内容:
......
[www]
user = php-fpm
group = php-fpm
listen = 127.0.0.1:9000
(补充:这里以让 php-fpm 监听本地 9000 端口为例)
3.3.4 启动 PHP 连接服务
# systemctl start php-fpm
步骤四:后续工作
1) 给 MariaDB 数据库设置用于存储网页数据的用户和密码
2) 将 PHP 网页程序放到 Nginx 的网页目录下
3) 给 PHP 网页程序设置用于连接 MariaDB 数据库的用户和密码
步骤五:测试 LNMP 平台
使用浏览器访问服务器 IP 地址就可以看到对应 PHP 网页了