I need to update the domain name for my website hosted through Digital Ocean.

I have the A records pointed to the new domain and the website displays, however when I run certbot, it only gives me the option for the old domain to generate a certificate.

My old domain is new.example.com and my new one is just example.com.

Please advise what I need to do to fix this and update the domain.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hi @harrywilson100,

First, you need to update your Apache configuration file and change the domain from example.com to new.example.com.

Usually, you can find the apache configuration file in the /etc/apache2/sites-enabled/ folder. In those files you need to change the following lines;

        ServerName example.com
        ServerAlias www.example.com

Once you do, don’t forget to restart Apache. After those change certbot should be able to find the proper domain when it’s being called.

The next thing would be to update the database of your website. What I mean is, your database will contain references to the old domain. You’ll need to update it with the new one.

Hello, @harrywilson100

Are you hosting the site on a plain Ubuntu droplet or you have a control panel like cPanel/WHM installed as well? The process may vary with the different configuration.

If you simply have a LAMP/LEMP stack droplet you will need to update your virtual hosts and also rename the file for the domain name as well. The location of the vhosts on Ubuntu droplet is the following: /etc/apache2/sites-available and a symlink in the /etc/apache2/sites-enabled directory as well.

You can open the configuration file of the domain name and then change the lines that KFSys already mentioned:

ServerName
ServerAlias

Also to rename the file you can just use mv :

mv yourdoman.com.conf newdomain.com.conf

Then you can check the Apache configuration for any syntax errors using this command:

sudo apachectl -t

If you get Syntax OK you can go ahead and restart Apache with this command:

service apache2 restart

If you’re using Nginx the location of the configuration files is /etc/nginx/sites-available/ and the line you need to change in the file is the server_name and then you can again rename the file to match the new domain name.

Test your the configuration file for syntax errors by typing:

sudo nginx -t

You will also need to change the domain name in the WordPress installation as well. You can check this question that was previously asked in our community in order to do that:

https://www.digitalocean.com/community/questions/change-url-in-wordpress?answer=59927

Hope that this helps!
Regards,
Alex