Skip to content

Instantly share code, notes, and snippets.

@cakmalik
Created May 7, 2025 23:26
Show Gist options
  • Save cakmalik/43781f1bce81d2c6e72d1b78334f41b4 to your computer and use it in GitHub Desktop.
Save cakmalik/43781f1bce81d2c6e72d1b78334f41b4 to your computer and use it in GitHub Desktop.
Clear webserver for Arch
#!/bin/bash
echo "🚨 Mulai proses penghapusan PHP, Web Server, dan MySQL dari sistem Anda..."
# Fungsi bantu hapus paket jika ditemukan
remove_pkg() {
local pattern="$1"
local pkgs=$(pacman -Qq | grep -E "$pattern")
if [[ -n "$pkgs" ]]; then
echo "🧹 Menghapus paket: $pattern ..."
sudo pacman -Rns --noconfirm $pkgs
fi
}
# 1. Hapus PHP dan turunannya
remove_pkg '^php|php[0-9]{2}|php-'
# 2. Hapus Web Server: Apache & Nginx
for svc in httpd apache nginx; do
sudo systemctl stop $svc 2>/dev/null
sudo systemctl disable $svc 2>/dev/null
done
remove_pkg 'apache'
remove_pkg 'nginx'
# 3. Hapus MySQL dan MariaDB
for svc in mysqld mysql mariadb; do
sudo systemctl stop $svc 2>/dev/null
sudo systemctl disable $svc 2>/dev/null
done
remove_pkg 'mysql'
remove_pkg 'mariadb'
# 4. Hapus dari AUR jika menggunakan yay atau paru
for aur_helper in yay paru; do
if command -v $aur_helper &>/dev/null; then
echo "🧹 Menghapus PHP, Web Server, dan MySQL dari AUR ($aur_helper)..."
aur_pkgs=$($aur_helper -Qq | grep -E 'php|apache|nginx|mysql|mariadb')
if [[ -n "$aur_pkgs" ]]; then
$aur_helper -Rns --noconfirm $aur_pkgs
fi
fi
done
# 5. Hapus phpbrew dan semua versinya
if command -v phpbrew &>/dev/null; then
echo "🧹 Menghapus phpbrew dan versinya..."
phpbrew list | awk '{print $1}' | tail -n +3 | xargs -I{} phpbrew remove {}
rm -rf ~/.phpbrew
fi
# 6. Hapus phpenv dan phpv jika ada
echo "🧹 Menghapus phpenv dan phpv..."
rm -rf ~/.phpenv ~/.phpv
# 7. Hapus konfigurasi dan file global
echo "🧹 Menghapus konfigurasi dan file global..."
sudo rm -rf /etc/php* /usr/lib/php* /usr/include/php* /usr/share/php*
sudo rm -rf /etc/httpd /etc/nginx /etc/mysql* /etc/mariadb*
sudo chattr -i -R /var/lib/mysql* /var/lib/mariadb* 2>/dev/null
sudo rm -rf /var/lib/mysql* /var/lib/mariadb*
sudo rm -rf /usr/lib/mysql* /usr/lib/mariadb* /usr/include/mysql* /usr/include/mariadb*
# 8. Hapus konfigurasi user
echo "🧹 Menghapus konfigurasi user..."
rm -rf ~/.config/php ~/.local/share/php ~/.mysql_history ~/.cache/mysql
# 9. Bersihkan PATH dan konfigurasi shell
echo "🧼 Membersihkan PATH dari phpbrew/phpenv..."
for file in ~/.bashrc ~/.zshrc ~/.profile ~/.bash_profile ~/.config/fish/config.fish; do
sed -i '/phpbrew/d' "$file" 2>/dev/null
sed -i '/phpenv/d' "$file" 2>/dev/null
done
# 10. Hapus cache pacman
echo "🧹 Menghapus cache pacman terkait..."
sudo rm -rf /var/cache/pacman/pkg/php* /var/cache/pacman/pkg/mysql* /var/cache/pacman/pkg/mariadb*
sudo journalctl --vacuum-time=1s 2>/dev/null
# 11. Verifikasi
echo "🔍 Verifikasi apakah PHP, Web Server, dan MySQL masih ada..."
for cmd in php httpd nginx mysql mariadb; do
if command -v $cmd &>/dev/null; then
echo "⚠️ Masih terdeteksi: $cmd -> $(which $cmd)"
fi
done
# 12. Cari sisa file terkait
echo "🔍 Mencari sisa file PHP, Web Server, dan MySQL..."
sudo find / \( -iname "*php*" -o -iname "*mysql*" -o -iname "*mariadb*" -o -iname "*httpd*" -o -iname "*nginx*" \) \
-not -path "/proc/*" -not -path "/sys/*" -not -path "/run/*" >~/sisa_lamp_files.txt
echo "📄 Daftar file tersisa disimpan di ~/sisa_lamp_files.txt"
echo "✅ Proses penghapusan selesai."
echo "🔁 Disarankan untuk me-restart sistem Anda agar semua perubahan diterapkan."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment