LNMP环境部署笔记

一、关闭防火墙 & SELinux

bash

运行

复制代码
systemctl stop firewalld
systemctl disable firewalld

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

二、安装依赖 & 扩展源

bash

运行

复制代码
yum install -y wget gcc gcc-c++ make
# CentOS 7
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# CentOS 8
# dnf install -y epel-release

三、安装 Nginx

bash

运行

复制代码
yum install -y nginx

systemctl start nginx
systemctl enable nginx

四、安装 MySQL(MariaDB)

bash

运行

复制代码
yum install -y mariadb-server mariadb

systemctl start mariadb
systemctl enable mariadb

初始化安全设置(执行后按提示设置 root 密码):

bash

运行

复制代码
mysql_secure_installation

五、安装 PHP 7.4(含常用扩展)

bash

运行

复制代码
# 先装 remi 源
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y yum-utils
yum-config-manager --enable remi-php74

# 安装 PHP 及扩展
yum install -y php php-fpm php-mysqlnd php-gd php-mbstring php-xml php-zip php-opcache

启动:

bash

运行

复制代码
systemctl start php-fpm
systemctl enable php-fpm

六、Nginx 配置 PHP 解析

新建 / 修改站点配置:

plaintext

复制代码
vim /etc/nginx/conf.d/default.conf

示例配置(直接替换):

plaintext

复制代码
server {
    listen       80;
    server_name  localhost;
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

检查配置并重启:

bash

运行

复制代码
nginx -t
systemctl restart nginx

七、测试 PHP 环境

bash

运行

复制代码
echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php

浏览器访问:

plaintext

复制代码
http://服务器IP/info.php

看到 PHP 信息页即成功。


八、常用服务命令

bash

运行

复制代码
# Nginx
systemctl start|stop|restart|status nginx

# MySQL/MariaDB
systemctl start|stop|restart|status mariadb

# PHP-FPM
systemctl start|stop|restart|status php-fpm
相关推荐
IT大白鼠2 小时前
Linux进程与计划任务管理:技术详解与实战指南
linux·运维·服务器
临街的小孩2 小时前
Docker 容器内运行 ROS Noetic 图形界面(rqt_image_view)极简教程总结
运维·docker·容器
hweiyu003 小时前
Linux命令:arptables
linux·运维
看到代码头都是大的4 小时前
Windows环境下绿色版nginx 1.30使用
运维·nginx
IT研究所4 小时前
AI 时代下的知识管理:从 Claude 的“复盘”能力看生成式 AI价值
大数据·运维·数据库·人工智能·科技·低代码·自然语言处理
仙柒4154 小时前
管理网络安全
linux·运维·服务器
云边云科技_云网融合4 小时前
企业出海的 “数字丝绸之路“:SD-WAN 如何重构全球网络竞争力
大数据·运维·网络·人工智能
JZC_xiaozhong4 小时前
2026年深圳企业如何统一管理ERP、MES、OA权限?身份识别与访问管理高效方案
大数据·运维·自动化·企业数据安全·数据集成与应用集成·权限治理·多系统权限管理
福尔摩斯·柯南5 小时前
Ubuntu 14.04/16.04/18.04/20.04/22.04/24.04/26.04全系列LTS长期支持版镜像IOS分享
linux·运维·ubuntu
xiaoming00185 小时前
JAVA项目打包部署运维全流程(多服务、批量)
java·linux·运维