cPanel Domain Control Menu Section

Remove cPanel Subdomain via SSH command line

I tried to remove an old subdomain from WHM/cPanel today through both List Subdomains in WHM and in Domains in cPanel and kept getting the following error.

cPanel List Domains to see your subdomains on the server

A fatal error or timeout occurred while processing this directive.[close]

(XID m384mg) This system does not have a domain named “subdomaintodelete.info”. at /usr/local/cpanel/Cpanel/Domain/Owner.pm line 57. Cpanel::Domain::Owner::get_owner_or_die(“subdomaintodelete.info”) called at whostmgr/bin/whostmgr2.pl line 2924 main::unpark(“unpark”) called at /usr/local/cpanel/Whostmgr/Dispatch.pm line 259 Whostmgr::Dispatch::_do_call(“unpark”, HASH(0x2acdeb8), HASH(0x2a909e8)) called at /usr/local/cpanel/Whostmgr/Dispatch.pm line 157 Whostmgr::Dispatch::dispatch(“unpark”, 1, ARRAY(0x2a8e398)) called at whostmgr/bin/whostmgr2.pl line 981

Well, the down and dirty on this one was just to edit the DNS Zone for the primary domain by deleting all references to domainodelete.com. Remember to Restart the DNS server to make sure changes are set.

cPanel Delete DNS Zone for each of the subdomain entries

Below shows where to restart the DNS in WHM. If you only have cPanel access, submit a ticket to your hosting provider to request a DNS Server reset.

Restart DNS Services after all of the subdomain entries are removed

However, I wanted it completely cleaned up on the server. So I was off to remove the subdomains manually via SSH.

I need to note that you will need root access to the server, for me this occurred on my VPS.

I SSHed into the server using Putty for my client in Windows. Once logged in I bumped myself  up to root authority.

 

Then I changed to the /etc/named directory

 

I then opened named.conf using my favorite editor vi to make sure none of the subdomains were listed and they were not.

 

I then checked the /var/named directory for any db files, again there were none.

Next I opened /etc/localdomains in vi

 

In here I found the subdomains I was looking for and I deleted the ones I no longer wanted.

I also checked the remote domain file for unwanted domains, of which I found none.

 

Finally the last place I looked was /etc/userdomains. I found the subdomains and deleted them.

After doing all of that, I went ahead and restarted Apache through WHM. Upon checking I still could not remove the domains. I kept getting the following error: Error: You do not have control of the domain domaintodelete.com

I then took the looked at /var/cpanel/users/cpanel-username and deleted the dmaintodelete.com DNS entries and XDNS entries. That took care of the domains in cPanel but not WHM.

Finally, I opened Apache’s httpd.conf file and deleted the virtual host for domaintodelete.com.

 

Be VERY CAREFUL with this, there are a number of lines for each Virtual Host and it is very easy to not delete enough or delete too much. Identify the beginning and end of the section beofre you begin to delete anything.

From there, I once again restarted Apache and I also restarted the DNS for good measure. Finally I refreshed WHM. Still no go, they were still there showing as parked.

Well during my time deleting Virtual Hosts, I noticed a *.conf reference at

 

Upon going the directory listed, I found an empty subdirectory for the subdomaintodelete.com and subdomaintodelete.maindomain.com. I deleted them both.

Restarted Apache and DNS and off to WHM, they were still there. The next step was to find all files on the vps with domaintodelete in the file name somewhere.

 

So here are all the directories where a file with that name showed up:

 

I went and deleted any files and folders associated with doaintodelete.com from each of those directories listed above manually. I am not sure if it was absolutely necessary, I just did it anyways.

This little project opened my eyes because as I was poking around, it was amaizing how much old information is still floating around in the files on the server, from old domains to old user account names buried throughout.

AS ALWAYS – USE THE ITEMS AT YOU OWN RISK and ALWAYS MAKE BACKUPS BEFORE MAKING CHANGES.

Tags: , , ,
Previous Post
WPMUDEV Domain Mapping
Softaculous WordPress MultiSite WPMUDEV XPro

Softaculous Staging – WPMUDEV Domain Mapping – APEX XPro Page Builder

Next Post
Visio
Microsoft Office Office 365 ProPlus Project Visio

Install Visio and Project Pro 2016 Standalone with Office 365 ProPlus

Leave a Reply

Your email address will not be published. Required fields are marked *