Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jesussuarz/21ffbf9a88773b7955e5965d205a4b2f to your computer and use it in GitHub Desktop.

Select an option

Save jesussuarz/21ffbf9a88773b7955e5965d205a4b2f to your computer and use it in GitHub Desktop.
Reinstall cPanel/WHM on Ubuntu After a Failed Installation (Without Reformatting the Server)

Reinstall cPanel/WHM on Ubuntu After a Failed Installation (Without Reformatting the Server)

cPanel does not provide an official uninstaller. If a cPanel installation fails, the usual recommendation is to reinstall the entire server.

However, it is possible to clean the existing installation and reinstall cPanel without formatting the server.

This guide explains how to remove the broken installation and perform a fresh install.

⚠️ Warning:
This process removes cPanel, MySQL/MariaDB, and all related data. Only use it on servers where data loss is acceptable or backups exist.


1. Stop and Remove MySQL / MariaDB

systemctl stop mariadb
apt purge mariadb* mysql* -y
apt purge 'cpanel*' -y
apt autoremove -y

2. Remove cPanel Files

First remove file attributes that may block deletion:

chattr -R -a /usr/local/cpanel/logs

Then delete all cPanel-related directories:

rm -rf /usr/local/cpanel
rm -rf /var/cpanel
rm -rf /etc/cpanel
rm -rf /var/lib/cpanel
rm -rf /var/log/cpanel*
rm -rf /var/lib/mysql
rm -rf /etc/mysql 
rm -rf /root/.my.cnf

3. Fix Package Issues

Clean and repair any broken packages before reinstalling:

apt --fix-broken install -y
dpkg --configure -a
reboot

4. Reinstall cPanel

Download and run the official installer:

cd /home && curl -o latest -L https://securedownloads.cpanel.net/latest && sh latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment