Apply free SSL using Let’s Encrypt (Ubuntu server & Laravel)

Mohamad Bachir Khoder
2 min readMay 12, 2024

--

Follow those steps with me to complete having free SSL using Let’s Encrypt on the Ubuntu server with a Laravel application.

Free SSL with Let’s Encrypt

steps:

1- Prepare your application environment.

2- Install Let’s Encrypt via the terminal.

Application:

To prepare your application environment:

1- Go to your Laravel application and replace all resources loaded with HTTP with HTTPS.

2- In your env file, put your domain in APP_URL; also add ASSET_URL. By doing that, resources using “asset()” will depend on the APP_URL of the env file.

APP_URL=https://your_domain.com
ASSET_URL="${APP_URL}"

3- If your application uses cookies, go to your config/session file and make sure that session_secure_cookie is true, so your application will only be sent back to the server if the browser has an HTTPS connection.

    'secure' => env('SESSION_SECURE_COOKIE',true),

4- Recheck and make sure our resources are correct and ready; look at everything, such as external links, CSS and JS files, and images; and be aware of tricky missing as any missing could affect your content after transforming into HTTPS.

To install Let’s Encrypt via the terminal:

go to your server and connect then on your terminal put the following

1- to install the latest version of Let’s Encrypt:

sudo apt update

2- install certbot (tool provided by Let’s Encrypt we will use to get SSL):

sudo apt install certbot python3-certbot-apache

While you are waiting for this to be done, you will face some questions, such as the following:

a-

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: yourdomain.com
2: www.yourdomain.com

Choose both by typing 1,2

b-

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

As our environment is ready, we will go with the second choice. If you later find an error with your content, you should edit your web server’s configuration as mentioned in the message.

3- obtain the certificate:

sudo certbot --apache

4- Automate Certificate Renewal:

sudo certbot renew --dry-run

5- Test Your Configuration:

After obtaining the SSL certificate, you can test your Apache configuration to ensure there are no syntax errors:

sudo apachectl configtest

It should give syntax OK.

6- Restart Apache:

If the test is successful, restart Apache to apply the changes:

sudo systemctl restart apache2

I hope this article was helpful!

--

--