Files
2026-06-13 10:51:37 -04:00

52 lines
1.5 KiB
Bash

#!/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 "------------------------------------------------"