温馨提示×

LNMP在Debian如何启动

小樊
38
2026-07-02 04:53:19
栏目: 智能运维

在 Debian 上,“LNMP”一般指 Linux + Nginx + MySQL(MariaDB) + PHP。启动 LNMP 实际就是分别启动 Nginx、MySQL/MariaDB、PHP-FPM 这几个服务。下面按常见情况说明。


一、使用 systemd 启动(推荐,Debian 8+ 通用)

1️⃣ 启动 Nginx

sudo systemctl start nginx
sudo systemctl enable nginx   # 开机自启

检查状态:

sudo systemctl status nginx

2️⃣ 启动 MySQL / MariaDB

如果是 MariaDB(Debian 默认)

sudo systemctl start mariadb
sudo systemctl enable mariadb

如果是 MySQL

sudo systemctl start mysql
sudo systemctl enable mysql

检查状态:

sudo systemctl status mariadb
# 或
sudo systemctl status mysql

3️⃣ 启动 PHP-FPM

先确认 PHP 版本,例如:

php -v

假设是 PHP 8.2:

sudo systemctl start php8.2-fpm
sudo systemctl enable php8.2-fpm

其他版本示例:

sudo systemctl start php7.4-fpm

检查状态:

sudo systemctl status php8.2-fpm

二、一次性启动 LNMP(组合命令)

sudo systemctl start nginx mariadb php8.2-fpm

三、检查 LNMP 是否正常运行

1️⃣ Nginx 是否监听 80 端口

ss -lntp | grep nginx

2️⃣ 数据库是否运行

mysql -u root -p

3️⃣ PHP 是否解析

/var/www/html 创建 info.php

<?php
phpinfo();

访问:

http://服务器IP/info.php

四、如果无法启动常见问题

❌ 端口被占用

sudo ss -lntp

常见冲突:Apache(80 端口)

❌ PHP-FPM socket 不存在

检查:

ls /run/php/

并确认 Nginx 配置中的:

fastcgi_pass unix:/run/php/php8.2-fpm.sock;

五、手动方式(不推荐)

sudo service nginx start
sudo service mariadb start
sudo service php8.2-fpm start

如果你愿意,我可以:

  • ✅ 给你一套 Debian 12 最新 LNMP 安装 + 启动完整流程
  • ✅ 检查你的 具体报错日志
  • ✅ 帮你排查 Nginx 502 / PHP 不解析问题

直接贴你的 Debian 版本:

cat /etc/debian_version

0