Daily Tech Tip: Removing a stray domain from a cPanel account
Ever have that problem were your user goes to add a domain and it says "Sorry: This domain is owned by another user". It could even be something other than that, but right now I will show you how to remove the domain from the account entirely in three easy steps.
Requirments
- Basic SSH Knowleddge
- Root access to server
Ok, the first step is to login to the server with the root account (some people may need to login and use su to obtain this.) First we need to know if it's an addon domain or parked domain, but operate in different ways. A parked domain is just an extra DNS entry and then added to another domains 'ServerAlias' in their VirtualHost directive. An add-on domain is a sub-domain of the users main domain and then the actual domain is parked on that sub-domain.
First we will need to open the users cPanel users file and investigate more. To do this we will need the users cPanel username.
Now it's as easy as running the following command (I assume we are using nano, if not use your text editor).
# nano /usr/local/apache/conf/httpd.conf
This will bring up your Apache configuration file. From there use CTL + W to bring up the search dialog and paste the domain in. Press enter; if no results come up there was an error writing the VirtualHost line to the httpd.conf and just close the file. If the domain is found and it's parked to a subdomain of the users, it's an add-on domain and remove the entire <VIRTUALHOST> to </VIRTUALHOST> for that domain. If it's the users main domain and then another domain, it's probably a parked domain, just remove the two lines (domain.tld and www.domain.tld) from the ServerAlias line and then save it. If the user specifies which one go with that they say (they probley know more than I do, and sometimes cPanel's messed up).
Knowing this we can no go into the users cPanel file and remove the domain. It's as simple as running this command.
nano /var/cpanel/users/USERNAMEHERE
Now knowing that data we had from before, we can tell if it's a parked domain or add-on domain, if it's a parked domain there will be one line for it, and if it's a parked domain there will be two. Go ahead now and delete the lines from this file containing the DNS names of the domain. After that exit the file and run the following command.
/scripts/updateuserdomains
Now it's as easy as logging into WHM and making sure all DNS entries are removed and having the user re-add the domain.
Please note this article is provided as a how-to and I can not be held responsible for any errors. If an error is occurred and you need any help please feel free to e-mail me at brandon[@]brandonlong[.]me and I will assist you as good as I can. With that said happy server administrating!