DeveloperBreeze

Renaming a subdomain in Apache and generating a new SSL certificate

Objective

We’ll rename an existing subdomain from old.example.com to new.example.com, update Apache configuration files, and generate a new SSL certificate using Certbot.


1. Rename and Update Configuration Files

First, rename your Apache configuration files to reflect the new subdomain name.

  1. Rename the Config Files: Use the mv command to rename the Apache config files for the new subdomain:
   sudo mv /etc/apache2/sites-available/old.example.com.conf /etc/apache2/sites-available/new.example.com.conf
   sudo mv /etc/apache2/sites-available/old.example.com-le-ssl.conf /etc/apache2/sites-available/new.example.com-le-ssl.conf
  1. Edit Configuration Files: Open each of the renamed files and replace any instance of old.example.com with new.example.com.
   sudo nano /etc/apache2/sites-available/new.example.com.conf

Make the necessary changes, save, and close the file. Repeat this step for the new.example.com-le-ssl.conf file as well.


2. Disable the Old Site and Enable the New One

Disable the old site and enable the newly configured site:

sudo a2dissite old.example.com.conf
sudo a2ensite new.example.com.conf

After enabling the new configuration, reload Apache for the changes to take effect:

sudo systemctl reload apache2

3. Generate a New SSL Certificate

Since the SSL certificate is tied to the specific domain name, you’ll need to create a new one for new.example.com. Certbot makes this easy.

Run the following command:

sudo certbot --apache -d new.example.com

This command will:

  • Generate a new SSL certificate for new.example.com.
  • Automatically update the new.example.com-le-ssl.conf file with the correct paths to the new SSL certificate.

4. Clean Up the Old SSL Certificate (Optional)

To keep things organized, you can remove the old SSL certificate for old.example.com if it’s no longer needed.

Use Certbot’s delete command:

sudo certbot delete --cert-name old.example.com

This will remove the certificate files associated with old.example.com.


5. Verify Everything is Working

After setting up the new configuration and SSL certificate, verify that Apache is running correctly:

  1. Check Apache Status:
   sudo systemctl status apache2
  1. Test Access in Browser:

Open your browser and visit https://new.example.com to ensure that it’s accessible with a valid SSL certificate.


By following these steps, you’ll successfully rename a subdomain from old.example.com to new.example.com and set up a fresh SSL certificate. This ensures your updated domain is secure and properly configured.

Related Posts

More content you might like

Tutorial
bash

How to Install and Configure Apache on Ubuntu

sudo systemctl start apache2
sudo systemctl stop apache2

Oct 21, 2024
Read More
Tutorial
bash

How to Create SSL for a Website on Ubuntu

Alternatively, you can use an SSL checker tool like SSL Labs to verify the validity of your SSL installation.

Let's Encrypt certificates are valid for 90 days. Certbot sets up automatic renewal by default, but it’s good practice to manually test it to ensure it’s working:

Oct 21, 2024
Read More
Tutorial

Adding a Subdomain on an Apache Server

   cd /var/www
   sudo mkdir -p /var/www/blog.example.com

Aug 21, 2024
Read More
Tutorial
python bash

Deploying a Flask Application on a VPS Using Gunicorn and Nginx

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d developerbreeze.com -d www.developerbreeze.com

Aug 03, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!