Published on November 07, 2024By DeveloperBreeze

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-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-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-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.

Comments

Please log in to leave a comment.

Continue Reading:

Adding a Subdomain on an Apache Server

Published on August 21, 2024

How to Create SSL for a Website on Ubuntu

Published on October 21, 2024

bash

How to Install and Configure Apache on Ubuntu

Published on October 21, 2024

bash