Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  SSL Issues & FAQ  >  How to Install Apache and Secure it with a Let’s Encrypt SSL Certificate?
Top Scroll

How to Install Apache and Secure it with a Let’s Encrypt SSL Certificate?

 2 min

Apache is one of the most widely used HTTP web servers. It’s used for setting up Apache and security with an SSL certificate.

In this article, we will learn how to set up Apache for your website on Ubuntu and CentOS.

Creating DNS Record

Login to Cloudflare or your domain registrar (if not Cloudflare) and create an A record to point the domain to the cloud VMs IP.

Refer to the image given below:

Creating DNS Record

Installing Apache (Ubuntu)

To update the available packages up-to-date:

sudo apt-get update
Install Apache
sudo apt-get install apache2

Allow ports 80 and 443 in your firewall for the HTTP server.

Type the command given below:

sudo ufw allow ‘Apache Full’
Check out that your installed Apache runs perfectly.
sudo systemctl status apache2

Configuring Apache to Serve the Important Files

Follow the steps given below to do so:

Create a folder for serving your web apps

sudo mkdir -p /var/www/

sudo vi /var/www/

Now paste the below HTML snippet for testing.

<!DOCTYPE html> <html lang=”en”> <head> <title>Apache webapp</title> </head> <body> <h1>My Apache webapp is working in</h1> </body> </html>

Then, you need to create a folder for generating and storing the logs.

Type the command given below:

sudo mkdir -p /var/www/ sudo touch

/var/www/ sudo touch


Open Conf file (Ubuntu)

To do so:

sudo vi /etc/apache2/sites-available/

Open conf file (CentOS)

sudo vi /etc/httpd/sites-available/

Paste the below conf snippet by making a change in your domain name.

<VirtualHost *:80>



DocumentRoot /var/www/

ErrorLog /var/www/

CustomLog /var/www/ combined


You will have to give the required permission for your folder.

sudo chown -R $USER:$USER /var/www/


sudo chmod -R 755 /var/www/

Enable your virtual host config file in apache(Ubuntu)

sudo a2ensite

First, disable the default conf file for security reasons.

sudo a2dissite 000-default.conf

Restart the Apache to make changes to take effect.

sudo systemctl restart apache2

Additional Setup for CentOS

In CentOS(SELinux), everything is not enabled by default like Ubuntu.

Create sites-enabled and sites-available folders in Apache.

sites-enabled – serves visitors with the cof files in it

sites-available – stores the virtual host conf files

sudo mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled

Tell the apache to read the conf file in the sites-enabled folder.

sudo vi /etc/httpd/conf/httpd.conf

Then, add the below line at end of the file

IncludeOptional sites-enabled/*.conf

Steps to Enable HTTPS

Enabling HTTPS in the Apache web server in Ubuntu is easy with the certbot and Let’s Encrypt.

Let’s Encrypt is a Certificate Authority that provides free SSL certificates for millions of websites.

On the other hand, Certbot is software that automatically sets up HTTPS for our website using Let’s Encrypt.

Adding and Install Certbot for Apache (Ubuntu)

Enter the commands given below:

sudo add-apt-repository ppa:certbot/certbot

sudo apt install python-certbot-apache

Adding and Installing certbot for Apache (CentOS)

sudo yum install epel-release
sudo yum install certbot python2-certbot-apache mod_ssl

Getting an SSL Certificate

sudo certbot –apache -d your-domain-name

This is how the verification is done by certbot with no issues. You will be asked for HTTPS redirection.

Choose option two and click on enter. That’s it!

Hope this article has given you an idea of how to install and execute an SSL certificate on Apache.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
Claim the discount before it’s too late. Use the coupon code:
Note: Copy the coupon code and apply it on checkout.