Locahl
Buy Locahl
HTTPSSSLcertificatemkcertlocal developmentmacOS

mkcert SSL Local: HTTPS Certificates on Mac

Set up mkcert SSL local certificates on Mac for localhost and .test domains. Copy the commands, configure Vite, Next.js, Docker and fix browser errors.

L

Locahl Team

Β·Updated Β·6 min read

Need mkcert SSL local certificates on Mac? Install mkcert with Homebrew, trust its local certificate authority, then generate a certificate for localhost or your .test development domain:

BASH
brew install mkcert
mkcert -install
mkcert localhost 127.0.0.1 ::1 myproject.test "*.myproject.test"

Use the generated .pem files in your local server config and your browser will treat the site as trusted HTTPS. This guide shows the full setup for localhost, custom domains, Vite, Next.js, Docker, Laravel Valet and common certificate errors.

Developing a PWA and Service Workers refuse to activate? Your app uses the Geolocation API and it only works in production? The culprit: no HTTPS locally. This guide shows you how to fix this permanently with mkcert.

Quick setup: mkcert SSL local on Mac

For most local development projects, this is the fastest path:

1. Install mkcert with Homebrew. 2. Run mkcert -install once to trust the local certificate authority. 3. Generate certificates for localhost, 127.0.0.1, ::1 and your custom .test domains. 4. Point your dev server to the certificate and key files. 5. Restart the browser if it still shows a certificate warning.

BASH
brew install mkcert
mkcert -install
mkdir -p certs
mkcert -cert-file certs/local-cert.pem -key-file certs/local-key.pem localhost 127.0.0.1 ::1 myproject.test "*.myproject.test"

You can now configure your server with certs/local-cert.pem and certs/local-key.pem.

Why HTTPS locally?

APIs that require HTTPS

Many modern web APIs only work in secure contexts (HTTPS):

  • Service Workers: Required for PWAs
  • Geolocation API: GPS location
  • Clipboard API: Copy/paste
  • WebRTC: Video/audio
  • Web Bluetooth: Bluetooth devices
  • Push Notifications: Push API

Other advantages

  • Dev/prod parity: Same behavior everywhere
  • Secure cookies: Test Secure and SameSite attributes
  • HTTP/2: Requires HTTPS
  • Credibility: No browser warnings

Installing mkcert

What is mkcert?

mkcert is a tool created by Filippo Valsorda that: 1. Creates a local certificate authority (CA) 2. Installs this CA in your system and browsers 3. Generates certificates signed by this CA

Result: your local certificates are recognized as valid.

Installation on Mac

BASH
# With Homebrew
brew install mkcert

# Install root certificates
mkcert -install

You'll see a message asking for your password to install the CA in the system keychain.

Verify installation

BASH
mkcert -CAROOT

Shows the folder containing your local CA.

Creating certificates

For localhost

BASH
mkcert localhost 127.0.0.1 ::1

Creates two files:

  • localhost+2.pem: The certificate
  • localhost+2-key.pem: The private key

For a custom domain

BASH
mkcert myproject.test

With wildcard (subdomains)

BASH
mkcert myproject.test "*.myproject.test"

Allows using api.myproject.test, admin.myproject.test, etc.

All-in-one certificate

BASH
mkcert localhost 127.0.0.1 ::1 myproject.test "*.myproject.test"

Configuring your server

Node.js / Express

JAVASCRIPT
const https = require('https');
const fs = require('fs');
const express = require('express');

const app = express();

const options = {
    key: fs.readFileSync('./localhost+2-key.pem'),
    cert: fs.readFileSync('./localhost+2.pem')
};

https.createServer(options, app).listen(3000, () => {
    console.log('HTTPS server running on https://localhost:3000');
});

Vite

JAVASCRIPT
// vite.config.js
import { defineConfig } from 'vite';
import fs from 'fs';

export default defineConfig({
    server: {
        https: {
            key: fs.readFileSync('./localhost+2-key.pem'),
            cert: fs.readFileSync('./localhost+2.pem')
        }
    }
});

Next.js

BASH
next dev --experimental-https --experimental-https-key certs/local-key.pem --experimental-https-cert certs/local-cert.pem

Recent Next.js versions can run the development server over HTTPS directly. If your setup needs custom routing or a proxy, use a custom server instead:

JAVASCRIPT
// next.config.js with custom server
const { createServer } = require('https');
const { parse } = require('url');
const next = require('next');
const fs = require('fs');

const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

const httpsOptions = {
    key: fs.readFileSync('./localhost+2-key.pem'),
    cert: fs.readFileSync('./localhost+2.pem')
};

app.prepare().then(() => {
    createServer(httpsOptions, (req, res) => {
        const parsedUrl = parse(req.url, true);
        handle(req, res, parsedUrl);
    }).listen(3000);
});

Webpack Dev Server

JAVASCRIPT
// webpack.config.js
const fs = require('fs');

module.exports = {
    devServer: {
        https: {
            key: fs.readFileSync('./localhost+2-key.pem'),
            cert: fs.readFileSync('./localhost+2.pem')
        }
    }
};

Using with custom domains

Configure the hosts file

To use myproject.test instead of localhost:

BASH
# /etc/hosts
127.0.0.1    myproject.test
127.0.0.1    api.myproject.test
Also readHow to edit the hosts file on Mac

Create the corresponding certificate

BASH
mkcert myproject.test "*.myproject.test"

Configure the server

Use the newly generated files in your server configuration.

Advanced use cases

Laravel Valet

Valet integrates mkcert natively:

BASH
valet secure myproject

That's it! Valet automatically generates and configures certificates.

Docker

YAML
# docker-compose.yml
services:
  web:
    volumes:
      - ./certs:/etc/nginx/certs:ro
    environment:
      - VIRTUAL_HOST=myproject.test
      - CERT_NAME=myproject.test

MAMP Pro

1. Preferences > Hosts 2. Select your host 3. SSL > Enable 4. Import your mkcert certificates

Troubleshooting

"NET::ERR_CERT_AUTHORITY_INVALID"

The CA is not installed in the browser.

BASH
mkcert -install

Then restart your browser. If the error persists after reinstalling the CA, follow the dedicated walkthrough on how to fix NET::ERR_CERT_AUTHORITY_INVALID for hostname-coverage and stale-certificate causes.

Chrome still ignores the certificate

Chrome may need a full restart:

BASH
# Mac
killall "Google Chrome"
open -a "Google Chrome"

If Chrome still shows NET::ERR_CERT_AUTHORITY_INVALID, confirm the certificate covers the exact hostname in the address bar. A certificate for localhost will not automatically cover myproject.test.

Firefox doesn't recognize the CA

Firefox uses its own certificate store. Install it manually: 1. Preferences > Privacy & Security > Certificates 2. View Certificates > Authorities > Import 3. Select rootCA.pem from mkcert -CAROOT

Best practices

Certificate organization

~/certs/
β”œβ”€β”€ localhost/
β”‚   β”œβ”€β”€ localhost+2.pem
β”‚   └── localhost+2-key.pem
β”œβ”€β”€ myproject.test/
β”‚   β”œβ”€β”€ myproject.test+1.pem
β”‚   └── myproject.test+1-key.pem
└── README.md

Never commit keys

GITIGNORE
# .gitignore
*.pem
certs/

Keep the certificate generation command in your README or setup script, but keep the generated key files out of Git.

Project setup script

BASH
#!/bin/bash
# setup-certs.sh
mkdir -p certs
cd certs
mkcert localhost 127.0.0.1 ::1 myproject.test "*.myproject.test"
echo "Certificates created in ./certs/"

Alternatives to mkcert

Work but generate constant browser warnings.

Tunnels (ngrok, localtunnel)

Expose your localhost on the Internet with HTTPS. Useful for mobile testing or webhooks.

Caddy

Web server with automatic HTTPS, even locally.

Conclusion

HTTPS locally is no longer optional in 2026. With mkcert, installation takes 2 minutes and saves you hours of frustration with modern APIs. Combine it with .test domains managed via Locahl for a professional development environment.

Share this article
Available on Windows, macOS & Linux

Ready to simplify your workflow?

Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.

  • Intuitive visual interface
  • Automatic DNS flush
  • Multi-environment management
  • Automatic backups
  • JSON Import/Export
Buy Locahl β€” $5.99One-time payment, no subscription

Reader Reviews

4.7β˜…(3 reviews)
Alex T.
β˜…β˜…β˜…β˜…β˜…

"mkcert changed my developer life. Never again SSL errors locally. Setup in 2 minutes thanks to this guide."

June 22, 2025

Lea M.
β˜…β˜…β˜…β˜…β˜…

"Finally a clear guide on local certificates. The Service Workers section unblocked me."

September 5, 2025

Damien P.
β˜…β˜…β˜…β˜…β˜…

"Great guide. Would have liked more details on Nginx configuration but otherwise perfect."

November 28, 2025

Frequently Asked Questions

Why do I need HTTPS in local development?

Certain modern APIs (Service Workers, Geolocation, Clipboard, WebRTC) only work over HTTPS. Plus, it avoids differences between dev and production.

What is mkcert?

mkcert is a tool that creates a local certificate authority and generates trusted SSL certificates for your development domains.

Are mkcert certificates secure?

For local development, yes. Never use mkcert in production. The certificates are only valid on your machine.

How do I use HTTPS with localhost?

After installing mkcert, run 'mkcert localhost' to create certificates, then configure your server to use them.

Does mkcert work with .test domains?

Yes, you can create certificates for any domain: mkcert myproject.test '*.myproject.test'

Why does my browser show NET::ERR_CERT_AUTHORITY_INVALID with mkcert?

Either the local mkcert CA is not trusted yet or the certificate does not cover the exact hostname in the address bar. Run mkcert -install, regenerate the certificate for that hostname, then fully restart the browser.

How do I use mkcert SSL local with Vite or Next.js?

Generate the cert and key files, then point the dev server at them. Vite uses server.https with key/cert paths; Next.js supports next dev --experimental-https with --experimental-https-key and --experimental-https-cert.

Related Articles

5 min read
mkcertHTTPSSSL

Fix mkcert NET::ERR_CERT_AUTHORITY_INVALID

Fix NET::ERR_CERT_AUTHORITY_INVALID with mkcert on Mac by reinstalling the local CA, regenerating certificates and checking hostnames.

L

Locahl Team

Developer tools team

9 min read
Dockerhosts filemacOS

Using Hosts Files for Docker Development on Mac

Configure hosts files for Docker, docker-compose and container networking. Map services to local domains and simplify Mac development.

L

Locahl Team

11 min read
LaravelWordPresslocal development

Hosts File Setup for Laravel and WordPress

Configure hosts files for Laravel Valet, Herd and WordPress local development with .test domains, multisite setups and best practices.

L

Locahl Team

8 min read
local developmentmacOSDocker

Local Development Environment on Mac (2026)

Set up a perfect local dev environment on macOS. MAMP vs Laravel Valet vs Docker comparison, .test domains, local HTTPS with mkcert. Complete checklist.

L

Locahl Team

6 min read
hosts filemacOStutorial

Edit the hosts file on Mac: Terminal vs GUI (2026)

How to edit /etc/hosts on macOS without errors? Terminal (sudo nano) vs GUI comparison. Fix permission denied and DNS cache issues in 2 minutes.

L

Locahl Team