Install and configure Apache with SSL on an EC2 Ubuntu instance for Free
- Update the package index on your instance:
sudo apt update
2. Install Apache web server:
sudo apt install apache2
3. Check if the Apache service is running:
sudo systemctl status apache2
4. If Apache is not running, start the service:
sudo systemctl start apache2
5. Enable Apache to start automatically at boot time:
sudo systemctl enable apache2
6. Check if Apache is accessible from a web browser by entering your instance’s public IP address or public DNS name in the browser’s address bar. You should see the Apache default page.
7. Install the Certbot tool to obtain SSL certificate from Let’s Encrypt:
sudo apt install certbot python3-certbot-apache
8. Obtain SSL certificate for your domain name:
sudo certbot --apache -d example.com -d www.example.com
9. Follow the on-screen instructions and provide necessary information such as email address to register with Let’s Encrypt and whether to redirect HTTP traffic to HTTPS.
10. After the certificate installation completes successfully, Certbot will configure the Apache web server to use SSL and redirect HTTP traffic to HTTPS.
11. Verify if SSL is working by accessing your website using HTTPS instead of HTTP. You should see a padlock icon in the browser’s address bar indicating that the connection is secure.
12. Check if SSL certificate renewal is set up automatically:
sudo systemctl status certbot.timer
That’s it! Now your Apache web server is configured to use SSL and you can access your website securely over HTTPS.
Bonus Section:
Check if the DNS records exist: Check if the DNS records exist for the domain name. You can use a tool such as nslookup or dig to check the DNS records. For example, run the following command to check the A record:
nslookup www.example.com