Securing your website with Let's Encrypt on CentOS 7 involves a few steps. Let's walk through the process step-by-step:
Prerequisites:
- Make sure you have root access to your CentOS 7 server.
- Ensure your domain is properly pointed to your server's IP address.
Install Certbot: Certbot is a client application that helps you obtain and manage Let's Encrypt SSL certificates. Install Certbot with the EPEL repository:
bashyum install epel-release
yum install certbot python2-certbot-apacheSet Up Apache: If you're using Apache as your web server, you'll need to enable the required modules:
bashyum install httpd
systemctl start httpd
systemctl enable httpdConfigure Firewall: Allow HTTP and HTTPS traffic through the firewall:
bashfirewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reloadObtain the SSL Certificate: Use Certbot to obtain an SSL certificate for your domain. Replace
domain.com
with your actual domain name:bashcertbot --apache -d domain.com -d www.
domain.comCertbot will guide you through the process, and you may need to provide an email address for renewal notifications.
Automate Certificate Renewal: Let's Encrypt certificates are valid for 90 days. To ensure your certificates are automatically renewed, set up a cron job:
bashcrontab -e
Add the following line to run the renewal check daily:
bash30 2 * * * /usr/bin/certbot renew >> /var/log/letsencrypt/renewal.log
Update Apache Configuration: Certbot will automatically update your Apache configuration to use the SSL certificate. However, you might need to adjust your virtual host settings to include the following lines:
bash<VirtualHost *:443>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/html
# SSL Configuration
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
# Other configurations as needed
</VirtualHost>Restart Apache: After making any configuration changes, restart Apache to apply the new settings:
bashsystemctl restart httpd
That's it! Your website should now be accessible over HTTPS with a valid SSL certificate from Let's Encrypt. Remember to periodically check your SSL certificate's expiration and ensure that the automatic renewal process is working correctly.