Removing Add-On Domains In CPanel Server On The Command Line

In cPanel, there is no native option to remove multiple add-on domains. The steps will help you to remove bulk Add-on domains via command line.

  1. Login to server as root and switch to cPanel user’s directory.

“# cd /var/cpanel/users

2.Take backup of username before editing it. If you make any mistake, you can restore from the backup file.

“# cp username username.bak     (Replace the username with main domain username)

3.In this file remove the DNS lines of both addon and sub domains lines and save it.

“# vi username  (Here you can remove it manually or follow the below ‘for’ loop to remove multiple add on domains)

Note: To remove bulk addon domains, first you need to take list of domain names in the “domains.txt” file, then use the below ‘for’ loop.

# cd /var/cpanel/users

# for i in `cat /root/domains.txt` ; do sed -i /$i/d username ; done

  1. Reload the userdomains to remove the addon domains from the userdomains list.

# /scripts/updateuserdomains

  1. Delete virtual host entry in Apache and delete the entry in cPanel addon domains list. Switch to “/var/cpanel/userdata/username” directory.

# cd /var/cpanel/userdata/username  (Replace the username with main domain username)

  1. Take a backup before editing it.

” # cp main main.bak

  1. In this file, remove all the addon and it’s respective sub domains entry and save it.

“# vi main

Note: To remove bulk addon and sub-domains, first you need to take list of add on domain names in the file “domains.txt” and sub-domains list in the “subdomain.txt” file. Then use the below ‘for’ loop.

“# cd /var/cpanel/userdata/username

# for i in `cat /root/domains.txt` ; do sed -i /$i/d ./main; done

# for i in `cat /root/subdomain.txt` ; do sed -i /$i/d ./main; done

  1. Also remove the add-on domain entry in the cache file in the same directory(/var/cpanel/userdata/username).

“# cp cache cache-bak

# vi cache

Note: To remove bulk addon and sub-domains, first you need to take list of add on domain names in the file “domains.txt” and sub-domain names in the “subdomain.txt” file respectively, then use the below for loop.

“# for i in `cat /root/domains.txt` ; do sed -i /$i/d ./cache; done

# for i in `cat /root/subdomain.txt` ; do sed -i /$i/d ./cache; done

  1. Then rebuild and restart Apache configuration to update the latest changes.

# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_default

# /scripts/rebuildhttpdconf

# /scripts/updateuserdomains

# service restart httpd

  1. Then remove the domain’s document root and it’s respective databases.

Note: For bulk removal, take the list of database in the “dblist.txt” file.

# for i in `cat /root/dblist.txt` ; do mysqldump $i > /backup/$i.sql; done  (If you need DB backup, take dump before dropping it)

# for i in `cat /root/dblist.txt` ; do mysqladmin -f drop $i; done

  1. Also remove the DNS zone file, you can remove the zone file using cPanel script.

# /scripts/killdns domainname

# for i in `cat /root/domain.txt` ; do /scripts/killdns $i ; done

Now verify the add-on domains in cPanel.

D KarthiKeyan