Assistanz
Assistanz

Removing Add-on domains in cPanel server on the command line

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

  1. 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)

  1. 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.

Most Popular:

Get The Latest Updates

Subscribe To Our Weekly Newsletter

No spam, notifications only about new products, updates.

DirectAdmin Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk
$ 99 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • NDA & SLA
  • SLA Review Meetings
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation
  •  

Platinum Support

24/7 Proactive Support
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Support

$ 30 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response Time
  • 4 Hours Resolution time for the Possible Issues
  • Security and Performance Optimization
  • React to Customers queries
  • Simple SignUp Process
  • Instant Account Activation
  • No Third party application support
  • No Migration and End User Support

Cpanel Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk

$ 99 Monthly / Server
  • 24/7 End User White Label Support
  • Unlimited Number of Tickets
  • Chat Support for Admin
  • Separate Account Manager
  • Guaranteed SLA
  • Weekly Status Reports
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation

Platinum Support

24/7 Proactive Server Management
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Server Management

$ 29 Monthly / Server
  • Unlimited Admin Tasks
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response time
  • 4 hours Response time for possible issues
  • Security and Performance Optimization
  • React to Customers queries
  • No Third party application support
  • No Migration and End User Support

Cpanel Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk

$ 99 Monthly / Server
  • 24/7 End User White Label Support
  • Unlimited Number of Tickets
  • Chat Support for Admin
  • Separate Account Manager
  • Guaranteed SLA
  • Weekly Status Reports
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation

Platinum Support

24/7 Proactive Server Management
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Server Management

$ 29 Monthly / Server
  • Unlimited Admin Tasks
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response time
  • 4 hours Response time for possible issues
  • Security and Performance Optimization
  • React to Customers queries
  • No Third party application support
  • No Migration and End User Support