温馨提示×

如何卸载linux lamp

小樊
46
2026-10-15 10:39:53
栏目: 智能运维

在 Linux 下“卸载 LAMP”通常指卸载 Linux + Apache + MySQL/MariaDB + PHP 这一套环境。下面按常见发行版给你几种做法,请先确认你是用什么方式安装的(系统包管理器 / 一键脚本 / Docker)。


一、先确认你是怎么装的

which apache2 httpd mysql mariadb php
  • Debian/Ubuntu 常见:apache2、mysql、php
  • CentOS/RHEL 常见:httpd、mariadb、php

二、Debian / Ubuntu(apt 安装)

1. 卸载 Apache

sudo systemctl stop apache2
sudo apt remove --purge apache2 apache2-utils
sudo apt autoremove --purge

2. 卸载 MySQL / MariaDB

sudo systemctl stop mysql
sudo apt remove --purge mysql-server mysql-client mysql-common
sudo apt autoremove --purge
sudo rm -rf /var/lib/mysql /etc/mysql

3. 卸载 PHP

sudo apt remove --purge php*
sudo apt autoremove --purge

三、CentOS / Rocky / Alma(yum / dnf)

1. 卸载 Apache

sudo systemctl stop httpd
sudo yum remove httpd

2. 卸载 MariaDB / MySQL

sudo systemctl stop mariadb
sudo yum remove mariadb-server mariadb
sudo rm -rf /var/lib/mysql

3. 卸载 PHP

sudo yum remove php php-*

四、如果你是用一键脚本装的(如 lnmp.org、宝塔)

宝塔面板

/etc/init.d/bt stop
wget -O uninstall.sh http://download.bt.cn/install/unnstall.sh
bash uninstall.sh

LNMP 一键包

cd lnmp安装目录
./uninstall.sh

五、清理残留(重要)

sudo rm -rf /var/www/html
sudo rm -rf /etc/apache2 /etc/httpd
sudo rm -rf /etc/php*

六、验证是否卸载干净

apachectl -v
mysql -V
php -v

都提示 command not found 即成功。


如果你愿意,可以告诉我:

  • 你的 Linux 发行版
  • 是 手动装 / apt / yum / 宝塔 / Docker

我可以给你精确的一条命令卸载方案。

0 踩