certbot ssl-certificate apache-configuration rename-subdomain a2dissite a2ensite apache-reload update-ssl remove-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.
- 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
- Edit Configuration Files: Open each of the renamed files and replace any instance of
old.example.com
withnew.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:
- Check Apache Status:
sudo systemctl status apache2
- 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.