How to Install Free SSL on Localhost
Installing SSL on localhost takes a few minutes and never involves a public certificate authority. No CA will sign a certificate for localhost, because nobody can prove they control it. What you do instead is create a small local CA, trust it on your machine, and issue certificates from it.
Why a public CA will not issue SSL for localhost
Let's Encrypt and other public certificate authorities only issue certificates for names you can prove you control on the public internet. Nobody controls localhost, so no trusted CA will sign a certificate for it. What you do instead is create your own tiny local certificate authority and get your browser and operating system to trust it.
The easy way to get SSL on localhost: mkcert
mkcert is a small tool that creates a local CA, installs it into your system and browser trust stores, and issues certificates from it. Install it with your package manager, then:
mkcert -install
mkcert localhost 127.0.0.1 ::1
You get a certificate file and a key file. Point your dev server at them. For an Express server, for example:
const fs = require('fs');
const https = require('https');
https.createServer({
cert: fs.readFileSync('localhost+2.pem'),
key: fs.readFileSync('localhost+2-key.pem')
}, app).listen(443);
Because the CA is in your trust store, the browser shows a real padlock with no warnings. The same flow on Apache-based stacks is covered in enabling HTTPS on localhost with XAMPP and WAMP.
The fallback: OpenSSL self-signed
If you cannot install mkcert, generate a self-signed certificate directly:
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout localhost.key -out localhost.crt \
-days 365 -subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost"
The subjectAltName line matters; modern browsers reject certificates that lack it, even when the common name is right. The details behind each flag are in generating an SSL certificate with OpenSSL. A self-signed certificate is not trusted by default, so you either import it into your OS trust store or accept the browser warning once per browser.
Choosing between the options
| Option | Browser warning | Best for |
|---|---|---|
| mkcert | None after install | Daily development |
| Self-signed | Yes, unless imported | Quick one-off tests |
| Plain HTTP | None on localhost | No secure APIs in use |
Notes that save time
- Certificates are bound to names. Include every name you use: localhost, 127.0.0.1, ::1, and any custom .test domain.
- Never reuse a localhost certificate on a public site; get a real free certificate there instead.
- If the browser still shows not secure after setup, restart it so it reloads the trust store. Firefox keeps its own store, which mkcert handles separately.
- Team members each need their own mkcert CA; do not commit certificates or keys to a shared repository.
Once HTTPS is running locally, test your staging or production domain with our free SSL certificate checker to confirm the same configuration will behave in front of real users. If you hit protocol-level errors while testing different setups, fixing ERR_SSL_PROTOCOL_ERROR covers the usual causes.
Testing with other devices
A localhost certificate only helps the machine that made it. To test on a phone or another computer, point that device at your machine's LAN address and give mkcert a certificate that includes it:
mkcert localhost 127.0.0.1 192.168.1.20
The other device must trust your local CA as well. mkcert prints the CA location with mkcert -CAROOT; copy the rootCA.pem file from there to the device and install it as a trusted certificate. On iOS and Android this takes a minute in the certificate settings. Skip this for anything sensitive: a CA private key that travels between machines can sign certificates for any site on those devices, so delete the CA when the testing is done.
When to skip HTTPS locally
Browsers already treat http://localhost as a secure context for most web platform features, so service workers and secure cookies often work on plain HTTP locally. Add a certificate when an API demands a real TLS connection, when a third-party SDK refuses non-HTTPS origins, or when you need to reproduce a mixed-content or redirect bug exactly as it behaves in production.
Related reading: self-signed certificates and HTTPS on a static site.
Frequently Asked Questions
Does localhost need HTTPS?
Browsers treat http://localhost as a secure context for most features. Add a certificate when an SDK, a cookie setting or a mixed content bug needs a real TLS connection.
Is a self-signed certificate enough for development?
Yes, if you import it into your trust store. Otherwise every browser session starts with a warning you have to click through.
Why does Firefox still warn after mkcert -install?
Firefox keeps its own trust store. Import the mkcert root there, or configure Firefox to use the system store.
Can I use the same localhost certificate on a staging server?
No. Use a real certificate there. A local CA is trusted only on machines you configured.
Where does mkcert keep its root?
It prints the path with mkcert -CAROOT. Copy rootCA.pem from there to any other device that must trust your local certificates.
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.