This HOWTO documents the steps to run Apache (httpd
) installed via Homebrew on macOS, serving content over HTTPS with Let’s Encrypt SSL certificates. The configuration avoids permission problems and port conflicts by using a neutral certificate directory and high-numbered ports.
Prerequisites
- macOS with Homebrew installed.
- Apache (
httpd
) installed with Homebrew:
- A valid Let’s Encrypt certificate for your host (obtained via
certbot
).
TL:DR – This is unnecessarily complex to debug really mostly due to Apple's decisions over the years about security and local web servers combined with the need to verify your connection to the computer over the Internet but once you crack it, you'll have a nice local web development environment on macOS that 'just works'.
Contents
Editing the Apache configuration
Edit the Apache configuration httpd.conf
file, it is in opt/homebrew/etc/httpd
HTTP is set to listen on port 8080 in the Homebrew HTTPD package. Best to leave this alone. Lower ports need root and it is better practice not to run this local web server as root.
Document Root is set to /opt/homebrew/var/www
in the Homebrew HTTPD package. This is a fine place to leave it but you can change it if you wish. I left it, I like defaults where possible.
Enable SSL modules in Apache
You can choose to use any text editor.
Uncomment these lines by removing the #
character at the start of the line:
Edit SSL configuration in Apache
Edit the Apache SSL configuration httpd-ssl.conf
file, it is in opt/homebrew/etc/httpd/extra
HTTPS is set to listen on port 8443 in the Homebrew HTTPD package. Best to leave this alone. Lower ports need root and it is better practice not to run this local web server as root.
Edit the SSL Virtual Host Context in this configuration file.
This is not setting up virtual hosts, (multiple host names for your web server) all we are doing, by uncommenting the Include in httpd.conf
is enabling the SSL virtual host in the httpd-ssl.conf
file.
Add your Let's Encrypt certificates
Server Certificate
Server Private Key
Notes:
- Use ports
8080
and8443
instead of80
and443
to avoid needing to run as root, which is better practice.
Place Certificates in a Neutral Location
Homebrew services run as your user. They cannot read the folder /etc/letsencrypt
directly. Instead, copy or symlink your certificates:
Start Apache via Homebrew Services
Verify Operation
Test HTTP:
Expected:
Test HTTPS:
Expected:
You should see a successful TLS handshake and the same page over SSL.
Auto-Renewal of Certificates
Let’s Encrypt certificates expire every 90 days. You should allow certbot
to renew them automatically and then refresh your copy in /opt/certs
.
Check renewal:
Once working, create a small script to sync the new certs into /opt/certs
:
Save as /usr/local/bin/refresh-certs.sh
, make it executable:
Add it to cron
or a launchd
job to run daily. Certbot handles renewal; your script ensures Apache always sees the latest files.
Common Issues
- Getting a valid certificate: Let’s Encrypt requires ports
80
and443
to be reachable from the public internet when issuing certificates. On a home or office network, this usually means forwarding those ports on your router to your Mac temporarily. Once the certificate is issued, you can continue to run Apache on8080
and8443
. - File permissions: Make sure the Homebrew service user (your macOS account) can read the certificate files. Using
/opt/certs
avoids permission errors. - Port conflicts: If something else is bound to
8080
or8443
, change the ports consistently in yourhttpd.conf
,httpd-ssl.conf
, and check your macOS firewall.
Conclusion
With the Apache server configuration file providing SSL support enabled, certificates relocated, and certificate information adjusted, Apache can serve secure content via Homebrew services without running as root. This is a practical setup for local development on macOS, with minimal changes to the configuration files and auto-renewal to keep certificates valid.
See Running Homebrew PHP on Apache on macOS Tahoe and Running Homebrew MySQL/MariaDB on macOS Tahoe.
Homebrew Logo: Vítor Galvão (creator); MikeMcQuaid, Synoli (committers), BSD, via Wikimedia Commons