It used to be pretty easy to remove a domain from my Virtual Private Server – dissable the site in apache, delete the files, delete the underlying database, and remove the domain from my DNS manager. Done.
With SSL certificates now a standard part of hosting websites (see here), this is complicated by the removal of those certificates. I am extremely grateful to the EFF for providing a free way to get SSL certificates through certbot and letsencrypt. Adding domains with certbot is pretty easy, but changing the domains with certificates is not so easy. In fact, it’s pretty complicated and there aren’t great directions out there (which is why I put this guide together).
In this guide, I’ll show you how to remove a domain from a virtual private server (I use linode.com) along with removing the SSL certificate. I was hosting a domain and website for a friend, but that person decided they no longer needed the domain. Here’s how I removed it.
First, it’s always a good idea to back up the files associated with the domain, just in case. I use phpMyAdmin to manage my SQL databases. Log in to your phpMyAdmin site, find the database associated with your site, and select Export.
You shouldn’t need to change any options, just select “Go” and phpMyAdmin will export the entire database.
To download all the files associated with your site, you can zip them from an SSH terminal or download them via FTP. I use Filezilla. Find the folder that contains all the files for your website and download the whole thing.
Now that you have a backup of everything, it’s time to start unmounting.
First, you should dismount your site in apache.
sudo a2dissite [domain]
You also need to dismount the site with encryption, which is the same command, but with the following addition:
sudo a2dissite [domain]-le-ssl.conf
Then reload your apache2 configuration:
service apache2 reload.
If you’ve done everything correctly, when apache reloads, there won’t be any errors.
Next, delete the certificate associated with your domain in certbot. To delete the certificate associated with a specific domain, the command is:
certbot delete –cert-name [enter domain here]
That will delete the certificate associated with that domain.
You may also need to update your certificate profile by using the command:
This will list all of the domains you have certificates for. You can then select all of the other domains on your server but drop the one you want to delete. That will create a new certificate with all of the domains minus the one you have deleted.
If you are wondering whether certbot has actually removed your domain, you can check by going to /etc/letsencrypt. You want to make sure that your domain is no longer showing up in either the /live, /renewal, or /archive folders. If you still see it in there, it should be safe at this point to delete any folders with the name of the domain in it.
Next, you can delete the corresponding database. In phpMyAdmin, click on “Server: localhost” then click on “Databases.” Select the box next to the database you want to delete, then, at the bottom, click “Drop”. You’ll get a warning about destroying a database. Select OK and the database is gone.
We’re almost done. Now, delete the files for your site. You can do this with the rm command from the terminal or using your FTP client.
Now, you should delete the apache site files that are located in /etc/apache2/sites-available. These are the two that were dismounted earlier: [DOMAIN].conf and [DOMAIN]-le-ssl.conf.
You can restart the apache service one more time to make sure everything is working, but you should be good.
Finally, you can delete the domain from your DNS manager.
That should do it. The domain should now be gone, entirely, from your server.
1,051 total views, 9 views today