# Apache 2 - Setup Free SSL using Certbot

SSL is important thing for the security for your web application, some of the SSL are paid features, but we can have free SSL provided by Let’s Encrypt. In this article, we're going to try to configure SSL on ubuntu + apache2 server.

### 1\. Install Required Packages

We need two packages in order to start creating SSL certficates, they are `certbot` and `python3-certbot-apache`.

```bash
sudo apt update
sudo apt install certbot python3-certbot-apache
```

### 2\. Configure Apache2 Virtual Host

in this case, I'm going to try to create a virtual host for magento245.dev.fiko.me. You just need to setup the port 80 and skipping the 443 port.

```bash
<VirtualHost *:80>
    ServerAdmin hi@fiko.me
    DocumentRoot /home/fiko/sites/magento245/pub/
    ServerName magento245.dev.fiko.me

    <Directory /home/fiko/sites/magento245/pub/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    <FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
    </FilesMatch>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```

then restart your apache2 by running:

```bash
sudo service apache2 restart
```

### 3\. Install SSL

Once you created the virtual host, try to create the certificate by running:

```bash
sudo certbot --apache
```

Follow the steps, and restart apache2 service.

---

Preferences:

* [https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-20-04](https://s.id/1FGso)
    
* [https://towardsdatascience.com/how-to-host-multiple-website-with-apache-virtual-hosts-4423bd0aefbf](https://s.id/1FGsA)
    
* [https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-20-04](https://s.id/1FGsD)
