From 39f594d78cf00bd2ff5bb4952a3d1cf1ff82ea87 Mon Sep 17 00:00:00 2001 From: fadmin Date: Sat, 13 Jun 2026 10:51:37 -0400 Subject: [PATCH] Add uninstall_lamp.sh --- uninstall_lamp.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 uninstall_lamp.sh diff --git a/uninstall_lamp.sh b/uninstall_lamp.sh new file mode 100644 index 0000000..d9c7453 --- /dev/null +++ b/uninstall_lamp.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Check for root privileges +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root (use sudo)" + exit 1 +fi + +echo "--- Starting LAMP Stack Uninstallation (Debian/Ubuntu) ---" + +# 1. Stop and Disable Services +echo "Stopping Apache and MariaDB..." +systemctl stop apache2 mariadb 2>/dev/null +systemctl disable apache2 mariadb 2>/dev/null + +# 2. Disable phpMyAdmin in Apache configuration +if command -v a2disconf &> /dev/null; then + a2disconf phpmyadmin > /dev/null 2>&1 +fi + +# 3. Purge Packages (Purge removes configuration files too) +echo "Purging Apache, MariaDB, PHP 8.2, and phpMyAdmin..." +apt purge -y apache2 mariadb-server php8.2* phpmyadmin +apt autoremove -y + +# 4. Delete Configuration Files and Data +read -p "Do you want to completely delete all Web files and Databases? (y/n): " CONFIRM +if [[ $CONFIRM == [yY] ]]; then + echo "Deleting /var/www/ and database directories..." + rm -rf /var/www/* + rm -rf /var/lib/mysql + rm -rf /etc/apache2 + rm -rf /etc/php + rm -rf /etc/phpmyadmin + echo "Files deleted." +else + echo "Skipping file deletion. Configs and Data remain in /etc/ and /var/." +fi + +# 5. Clean Firewall Rules +if command -v ufw &> /dev/null; then + echo "Updating UFW rules..." + ufw delete allow 'Apache Full' > /dev/null 2>&1 +fi + +# 6. Clean Package Cache +apt clean + +echo "------------------------------------------------" +echo "Uninstallation Complete!" +echo "The LAMP stack and PHP 8.2 have been completely removed." +echo "------------------------------------------------" \ No newline at end of file