温馨提示×

Debian LAMP怎么启服务

小樊
47
2026-10-25 08:39:29
栏目: 智能运维

在 Debian 上搭建 LAMP(Linux + Apache + MySQL/MariaDB + PHP)后,启服务通常用 systemd。下面按组件说明。


一、Apache 启停

# 启动
sudo systemctl start apache2

# 停止
sudo systemctl stop apache2

# 重启
sudo systemctl restart apache2

# 开机自启
sudo systemctl enable apache2

# 查看状态
sudo systemctl status apache2

Debian 中 Apache 服务名是 apache2


二、MySQL / MariaDB 启停

如果你装的是 MariaDB(Debian 默认)

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb

如果你装的是 MySQL

sudo systemctl start mysql
sudo systemctl enable mysql
sudo systemctl status mysql

三、PHP(不需要单独启服务)

PHP 一般通过 Apache 模块或 PHP-FPM 运行:

1️⃣ Apache + PHP 模块(最常见)

sudo apt install php libapache2-mod-php
sudo systemctl restart apache2

2️⃣ PHP-FPM(可选)

sudo apt install php-fpm
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

四、一键检查 LAMP 状态

systemctl status apache2 mariadb php-fpm

五、防火墙(如启用)

sudo ufw allow 80
sudo ufw allow 443

六、测试是否成功

新建测试页:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

浏览器访问:

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

如果你愿意,我可以按 具体 Debian 版本(11/12) 或 是否用 Docker 给你更精确的命令。

0 踩