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
相关推荐
乘云数字DATABUFF2 天前
5分钟部署开源APM Databuff:OpenTelemetry全链路追踪入门实战
运维·后端
荣--4 天前
一键部署不是为了省时间 —— 它是把"买来的 PaaS"变成"自己的平台"的拐点
运维·zabbix·工程化·一键部署·平台化·边界设计
江华森4 天前
动手实战学 Docker — 从零到集群编排完全指南
运维
Avan_菜菜4 天前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
SelectDB5 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode7 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220707 天前
如何搭建本地yum源(上)
运维
大树8810 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠10 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质10 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务