Introduction

Apache is one of the most widely used HTTP web servers. Setting up the apache and securing it with an SSL cert is the first step you need to do for your web applications. In this tutorial, you will learn how to set up Apache for your website on Ubuntu and CentOS. I’ve tested this on DigitalOcean VM. For the demonstration purpose. I’m going to use the test domain name test.sanakil.xyz, which is supercharged by Cloudflare.

DNS Record Creation

Login to Cloudflare or your domain registrar (if not Cloudflare) and create an A record to point the domain to the cloud VM’s IP. Log in to your cloud server via SSH.

Installing Apache(Ubuntu)

To update the available packages up-to-date Install apache Allow ports 80 and 443 in your firewall for the HTTP server. Check that your installed apache running correctly

Installing Apache(CentOS)

Update the available packages up-to-date. Install Apache Add ports 80 and 443 in the firewall to access the web app. Start apache and check the running status

Create VirtualHost for the website

A virtual host can be created in two ways depending upon which type of web app/ website we serve. Suppose the application already has a web server like Node running on a port. We can use a proxy to serve it in apache. Or if the app is just serving the files like static sites. We can specify the path of the application to serve in apache. Create a Virtual host file in apache – the configuration file can be in any name. But keeping it with the domain name which we are going to serve the web app will be better for easy identification.

Additional setup for CentOS

In CentOS(SELinux), not everything is enabled by default like Ubuntu. We have to create sites-enabled and sites-available folders in apache. sites-enabled – tells apache to serve visitor with the conf files in it sites-available – store the virtual host conf files Now tell the apache to read the conf file in the sites-enabled folder. Add the below line at the end of the file

Configure Apache to serve files

Create a folder for serving your web app

Paste the below HTML snippet for testing

Create a folder to generate and store logs

Open conf file(Ubuntu)

Create a symbolic link for apache Enable your virtual host config file in apache(CentOS) Restart apache to make changes to take effect. Let’s Encrypt is a non-profit organization which provided SSL certificate for millions of website free. Certbot is software that will automatically set up HTTPS for our website using let’s encrypt.

Add and install certbot for apache(Ubuntu)

Add and install certbot for apache(CentOS)

Get SSL certificate If all the verification is done by certbot without any issues. It will ask for HTTPS redirection. Select option 2 and enter. That’s it. If everything works correctly, https://test.sanakil.xyz will show a basic HTML index page that we have created.

Conclusion

I hope this gives you an idea about installing and implement an SSL certificate on Apache. Next, find out how to implement a certificate in Nginx.

How to Install Apache and Secure with Let s Encrypt Certificate  - 99How to Install Apache and Secure with Let s Encrypt Certificate  - 7How to Install Apache and Secure with Let s Encrypt Certificate  - 21