There's something to be said for developing on virtual machines that are a one-to-one replica of production environments. I will never deny that.
But... there's also something to be said about using Homebrew for my development needs and it giving me the least amount of problems. Docker's endless configuration, Canonical's multipass mac firewall issue, UTM's gui cruft that I don't need, etc. This is my reminder doc about how I've set up homebrew to do web development.
- Brew for installing packages like nginx, php, and mariadb
- A centralized code folder
- mkcert for locally-trusted development certificates
- Easy to start and stop daemonized services
Brew gives me all of the tools on macOS that I would expect when setting up a production server on Ubuntu. All code goes into ~/Developer
so I can easily get to everything in one spot. AND... I use mkcert
to generate certificates that I can use locally by wiring them up in nginx. Being able to test https locally is essential.
Dead simple daemon control comes with brew services
so I can launch web services and shut them down at will.
Homebrew, the missing package manager for macOS (or linux).
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This will install everything to the prefix /opt/homebrew
including things like nginx/postgres configuration. On a typical Ubuntu sytem, you'll find nginx configuration at /etc/nginx
. This path becomes /opt/homebrew/etc/nginx
on macOS.
I use mkcert
to generate local development certicates and add entries to /etc/hosts
to map domains to nginx. You can setup dnsmasq
to resolve a domain suffix of your choice but I have avoided this because there have been issues with people masking entire TLDs like .local
and .dev
and messing up thier networks and access to websites. I personally like using .dev
mapped to my hosts file but I avoid using domains that map to real world domains like wordpress.dev.
brew install mkcert
mkcert macos.dev "*.macos.dev" localhost 127.0.0.1 ::1
sudo nano /etc/hosts
Watch for any help messages you need to be aware of during install. These are the very basics for a LEMP environment using latest packages along with git for code repository management.
brew install git nginx mariadb php
brew services start nginx
brew services start mariadb
brew services start php
The port for the homebrew nginx formula has been set to 8080 so you don't have to use sudo to start the services. You can access the clean Nginx start page at localhost:8080.
I use port 8080 (http) and 8443 (https) on Nginx and when I'm running Apache alongside Nginx, I map Appache to 9080 and 9443. You'll need to edit your Apache startup configuration to Listen on 9080 in order to run Nginx and Apache side-by-side.
One of the domains I've mapped to my /etc/hosts
file is macos.dev
127.0.0.1 macos.dev
After generating the certificate in ~/Developer
...
mkcert macos.dev "*.macos.dev" localhost 127.0.0.1 ::1
I updated the ssl block in /opt/homebrew/etc/nginx.conf
to reflect a development certificate. This process can repeated for each configuration file under /opt/homebrew/etc/servers/
.
server {
listen 8443 ssl;
server_name macos.dev;
ssl_certificate /Users/kalebheitzman/Developer/macos.dev+4.pem;
ssl_certificate_key /Users/kalebheitzman/Developer/macos.dev+4-key.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
nano /opt/homebrew/etc/httpd/httpd.conf
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 9080