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
相关推荐
数智化精益手记局1 小时前
什么是安全生产?解读安全生产的基本方针与核心要求
大数据·运维·人工智能·安全·信息可视化·自动化·精益工程
zjeweler1 小时前
好淘云:低成本云服务器选型与实战应用指南
运维·服务器
空管电小二1 小时前
【低压断路器的选择性配合】低压配电“安全后盾“:后备保护到底是什么?
运维·经验分享·安全·学习方法
奇妙之二进制1 小时前
zmq源码分析之PUSH/PULL 模式的负载均衡分析
运维·网络·负载均衡
wheeldown2 小时前
2026年4月横评三款主流远控软件实况实测:UU远程,Todesk,向日葵,综合性能 UU 远程表现最佳
linux·运维·服务器
小夏子_riotous2 小时前
Docker学习路径——8、Dockerfile
linux·运维·docker·容器·系统架构·centos·运维开发
2601_955256472 小时前
服务器日志管理最佳实践:logrotate配置详解、云日志服务对比与Docker日志限制方案
运维·服务器·docker
切糕师学AI2 小时前
Docker Compose 完全指南:从入门到实践
运维·docker·容器
叶子上的考拉2 小时前
解决远程连接服务器反应较慢问题
linux·运维·服务器
lazybird742 小时前
vmware装的ubuntu22.04, 在vmware中将磁盘由40G调整为50G后,ubuntu中还需要进行调整
linux·运维·服务器