How to Set Up Local SSL on Ubuntu with mkcert and NGINX

new laravel12 project setup for how to install local ssl

Learn how to enable HTTPS locally on Ubuntu using mkcert, NGINX, and Laravel. This guide sets up lara12proj.local with a trusted self-signed certificate — perfect for secure local development.

I’m using a LARAVEL PROJECT for this tutorial, you can use this process for Nodejs project etc

Environment:

  • Linux: Ubuntu 24.04.2 LTS
  • node -v 24.0.2 (i’m using nvm)
  • npm -v 11.4.0
  • SSL repo: FiloSottile/mkcert [54.2k stars]

https://github.com/FiloSottile/mkcert

This package is well maintained, written in GO language and i’m using it since 2022 for my local development.

mkcert github easy way to setuo local ssl

Final preview of https:// SSL once you followed below steps

After follow below steps here is the final preview of SSL secure local domain

local ssl preview

Install new Laravel project – you can create Node or Remix site as well

new laravel12 project setup for how to install local ssl

Step 1: Install mkcert – (SSL for local)

sudo apt install libnss3-tools -y

curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"
chmod +x mkcert-v*-linux-amd64
sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert

Check mkcert Version

mkcert --version

v1.4.4

Step 2: Install Local CA

mkcert -install

The local CA is already installed in the system trust store! 👍
The local CA is already installed in the Firefox and/or Chrome/Chromium trust store! 👍

Create directory for storing local SSLs

sudo mkdir -p /etc/ssl/localcerts

Create new SSL

you can run mkcert lara12proj.local in ~/Download Folder, in ~/Documents Folder etc, but set a write path when we moved such certificates into /etc/ssl/localcerts

mkcert lara12proj.local

## in laravel project, or in ~/Documents run `mkcert lara12proj.local`

## move certificates
sudo mv /var/www/html/lara12proj.local/lara12proj.local*.pem /etc/ssl/localcerts/

sudo chmod 600 /etc/ssl/localcerts/lara12proj.local-key.pem
sudo chmod 644 /etc/ssl/localcerts/lara12proj.local.pem

once you ran mkcert lara12proj.local it’ll create 2 files

  • lara12proj.local.pem
  • lara12proj.local-key.pem
mkcert and ssl files created laravel
mkcert ssl files created

use ll /etc/ssl/localcerts it’ll show the SSL files moved in /etc/ssl/localcerts directory.

ssl certificates pem previw

Now create Nginx virtual host file

sudo nano /etc/nginx/sites-available/lara12proj.local.conf

and paste below code in lara12proj.local.conf and after paste use Ctrl+s then Ctrl+x for exit from terminal.

#lara12proj.local.conf

server {
    listen 80;
    server_name lara12proj.local;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name lara12proj.local;

	ssl_certificate     /etc/ssl/localcerts/lara12proj.local.pem;
	ssl_certificate_key /etc/ssl/localcerts/lara12proj.local-key.pem;



    root /var/www/html/lara12proj.local/public;
    index index.php index.html index.htm;

    access_log /var/log/nginx/lara12proj_access.log;
    error_log /var/log/nginx/lara12proj_error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;  # Adjust PHP version if needed
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Update hosts

sudo nano /etc/hosts

# and paste below code at last
127.0.0.1 lara12proj.local

Restart Nginx and PHP FPM

sudo nginx -t
sudo systemctl reload nginx

sudo systemctl reload php8.2-fpm (optional)

Update .env file in Laravel project

add https in APP_URL e.g. APP_URL=https://lara12proj.local

set domain in env file and use https

Restart Chrome or Firefox

make sure you have run mkcert -install otherwise you may receive some errors. TRY to restart your system as well if any error you face.

https://lara12proj.local/

Leave a Reply

Your email address will not be published. Required fields are marked *