Trusted HTTPS for local WordPress on Ubuntu and Debian
Make your own local certificate authority, sign a certificate for each site and have every browser trust it, without a warning page.
A local site on plain HTTP works until it does not: secure cookies, payment sandboxes, service workers and a lot of plugins expect HTTPS. A self-signed certificate gets you HTTPS with a warning page on every visit. The fix is the way the web itself works: a certificate authority your machine trusts, and a certificate for each site signed by it.
Pick a name that stays local
Use a name that can never exist on the internet:
.testis reserved for testing (RFC 2606), solocal.spellbook.testis safe..localhostis reserved for this machine (RFC 6761), and browsers sendshop.localhostto 127.0.0.1 without a hosts line.- Avoid
.devand.app: they are real top-level domains, and browsers force HTTPS on them through the HSTS preload list.
Point the name at this machine in /etc/hosts:
echo '127.0.0.1 local.spellbook.test www.local.spellbook.test' | sudo tee -a /etc/hosts
Make a local certificate authority
Once per machine, make the authority's key and its certificate. Keep the key private: anything it signs, this machine will trust.
mkdir -p ~/local-ca && cd ~/local-ca
openssl genrsa -out local-ca.key 4096
openssl req -x509 -new -nodes -key local-ca.key -sha256 -days 1825 \
-subj "/CN=Local Dev CA" -out local-ca.pem
Trust it in the system store, which curl, PHP and most programs read:
sudo cp local-ca.pem /usr/local/share/ca-certificates/local-dev-ca.crt
sudo update-ca-certificates
The file in /usr/local/share/ca-certificates must end in .crt, or
update-ca-certificates skips it.
Trust it in your browsers
Chrome, Chromium and Edge on Linux read the NSS database in your home folder,
not the system store. Add the authority with certutil from libnss3-tools:
sudo apt install libnss3-tools
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n "Local Dev CA" -i ~/local-ca/local-ca.pem
Firefox keeps a database per profile. Run the same command with the profile's
folder (under ~/.mozilla/firefox/, or ~/snap/firefox/common/.mozilla/firefox/
for the snap), or import local-ca.pem in Firefox's settings under
Certificates, Authorities. Restart the browsers afterwards.
Sign a certificate for each site
A browser only accepts a certificate that lists the site's names in its Subject Alternative Name, so write them in an extension file:
cd ~/local-ca
cat > local.spellbook.test.ext <<'EOF'
basicConstraints=CA:FALSE
keyUsage=digitalSignature,keyEncipherment
extendedKeyUsage=serverAuth
subjectAltName=DNS:local.spellbook.test,DNS:www.local.spellbook.test
EOF
openssl req -new -nodes -newkey rsa:2048 -keyout local.spellbook.test.key \
-subj "/CN=local.spellbook.test" -out local.spellbook.test.csr
openssl x509 -req -in local.spellbook.test.csr -CA local-ca.pem -CAkey local-ca.key \
-CAcreateserial -days 397 -sha256 -extfile local.spellbook.test.ext -out local.spellbook.test.crt
Serve it from Apache
Give the site a vhost on port 443, saved as
/etc/apache2/sites-available/local.spellbook.test-ssl.conf:
<VirtualHost *:443>
ServerName local.spellbook.test
ServerAlias www.local.spellbook.test
DocumentRoot /var/www/local.spellbook.test
SSLEngine on
SSLCertificateFile /home/you/local-ca/local.spellbook.test.crt
SSLCertificateKeyFile /home/you/local-ca/local.spellbook.test.key
</VirtualHost>
Then turn on Apache's SSL module and the site:
sudo a2enmod ssl
sudo a2ensite local.spellbook.test-ssl
sudo apache2ctl configtest && sudo systemctl reload apache2
Open https://local.spellbook.test: the lock shows, with no warning.
Or let the tools do it
All of the above is what the tools on this site do for you, on the same setup:
- devmagic CLI:
devmagic -d local.spellbook.test -cimakes the authority and adds it to the system store once (Firefox needs it imported by hand), and-c -cfsigns the site's certificate, writes the SSL vhost and adds the hosts line. - devmagic-panel: its installer makes a local CA and
trusts it in the system, Chrome, Edge and Firefox. Every new site gets one
certificate that covers all of its domains, and the Aura page reissues the
ones that miss a name or will soon expire. It only ever signs local names
(
local.*,www.local.*,*.test,*.localhost), so it cannot make a trusted certificate for a real domain.