HTTPS locally on Mac: create SSL certificates with mkcert (2026)
How to enable HTTPS in local development on Mac? Step-by-step mkcert guide. Trusted certificates for localhost and .test domains without browser errors.
Locahl Team
Table of Contents
- Why HTTPS locally?
- APIs that require HTTPS
- Other advantages
- Installing mkcert
- What is mkcert?
- Installation on Mac
- Verify installation
- Creating certificates
- For localhost
- For a custom domain
- With wildcard (subdomains)
- All-in-one certificate
- Configuring your server
- Node.js / Express
- Vite
- Next.js
- Webpack Dev Server
- Using with custom domains
- Configure the hosts file
- Create the corresponding certificate
- Configure the server
- Advanced use cases
- Laravel Valet
- Docker
- MAMP Pro
- Troubleshooting
- "NET::ERR_CERT_AUTHORITY_INVALID"
- Chrome still ignores the certificate
- Firefox doesn't recognize the CA
- Best practices
- Certificate organization
- Never commit keys
- Project setup script
- Alternatives to mkcert
- Self-signed certificates (not recommended)
- Tunnels (ngrok, localtunnel)
- Caddy
- Conclusion
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.
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
Simplify your hosts file management
Locahl lets you manage your hosts file visually, without touching the terminal. Automatic DNS flush, multiple environments, and backups included.
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
# With Homebrew
brew install mkcert
# Install root certificates
mkcert -installYou'll see a message asking for your password to install the CA in the system keychain.
Verify installation
mkcert -CAROOTShows the folder containing your local CA.
Creating certificates
For localhost
mkcert localhost 127.0.0.1 ::1Creates two files:
localhost+2.pem: The certificatelocalhost+2-key.pem: The private key
For a custom domain
mkcert myproject.testWith wildcard (subdomains)
mkcert myproject.test "*.myproject.test"Allows using api.myproject.test, admin.myproject.test, etc.
All-in-one certificate
mkcert localhost 127.0.0.1 ::1 myproject.test "*.myproject.test"Configuring your server
Node.js / Express
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
// 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
// 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
// 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:
# /etc/hosts
127.0.0.1 myproject.test
127.0.0.1 api.myproject.testCreate the corresponding certificate
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:
valet secure myprojectThat's it! Valet automatically generates and configures certificates.
Docker
# docker-compose.yml
services:
web:
volumes:
- ./certs:/etc/nginx/certs:ro
environment:
- VIRTUAL_HOST=myproject.test
- CERT_NAME=myproject.testMAMP 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.
mkcert -installThen restart your browser.
Chrome still ignores the certificate
Chrome may need a full restart:
# Mac
killall "Google Chrome"
open -a "Google Chrome"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.mdNever commit keys
# .gitignore
*.pem
certs/Project setup script
#!/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
Self-signed certificates (not recommended)
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.
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
Reader Reviews
"mkcert changed my developer life. Never again SSL errors locally. Setup in 2 minutes thanks to this guide."
June 22, 2025
"Finally a clear guide on local certificates. The Service Workers section unblocked me."
September 5, 2025
"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'
Related Articles
Using Hosts Files for Docker Development on Mac
Learn how to configure hosts files for Docker, docker-compose, and container networking. Map container services to local domains and streamline your Docker development workflow.
Locahl Team
Hosts File Setup for Laravel/WordPress Local Development
Complete guide to configuring hosts files for Laravel Valet, Herd, and WordPress local development. Learn custom domains (.test, .local), multisite configurations, and best practices.
Locahl Team
Local development environment on Mac: the complete guide (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.
Locahl Team