Error from domain wrapper: Domain already exists, it was not added.: cPanel

So, today i had this guy that added some domain, a subdomain and then after removing, he wanted to add it once more, but got the error below:

Error from domain wrapper: Domain already exists, it was not added.

This means that after the deletion, there have been some bits and pieces of info that got left over at deletion. Doesn’t happen that often but here’s what you can do to fix it: (info provided by Tristan at the cPanel forums)

You would want to check the following locations:

/var/cpanel/userdata/username/main
/var/cpanel/userdata/username/sub.maindomain.com
/var/cpanel/users/username
/var/named/maindomain.com.db

Any of the above if it has traces of the subdomain will cause the subdomain to continue to be considered existing on the system. Simply make a copy of the file you are editing and then remove the subdomain. For the /var/cpanel/userdata/username/sub.maindomain.com file, simply move the file out of the way. For the /var/named/maindomain.com.db file, you could edit it in WHM > Edit a DNS zone if the subdomain is still there rather than edit that file directly.

If you did find the subdomain listed in any of the /var/cpanel/userdata/username files, you would need to run the following commands after removing it in the main file there and moving the sub.maindomain.com file there:

cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak110217
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart

You would also likely want to run this script after that or possibly after editing /var/cpanel/users/username file:

/scripts/updateuserdomains

If you directly edited the /var/named/maindomain.com.db file rather than editing it in WHM > Edit a DNS Zone, you’d need to run this command:

rndc reload

In all of the above, username is the cPanel username, maindomain.com is the main domain name, andsub.maindomain.com is the subdomain name.

For me the problem was that /var/cpanel/users/username had 2 lines referring to the old domain. Removed those, updated userdomains as instructed, then rebuilt the httpd.conf, reload apache and there you go.