geoffthompson

Installing Nginx on Mac OS Sonoma

I need to get a local web server running to develop PHP and Node web applications.

I am running Mac OS Sonoma 14.5 on a 2023 MacBook Pro with Apple M3 Pro chip, so these downloads and steps may not work for those with other OS versions or hardware configurations.

I started with ChatGPT, which provided excellent instructions, although they were slightly inaccurate. Below are the steps I took, as modified from the original ChatGPT instructions.

Install Nginx

$ brew update
$ brew upgrade
$ brew install nginx
$ brew services start nginx

Open a browser and go to http://localhost:8080 and you should see a "welcome to Nginx" landing page. If so, the installation is a success.

Configure Nginx

The default Nginx installation (on Sonoma) is in /opt/homebrew/ and the default config file is in /opt/homebrew/etc/nginx.

I prefer to use the default port 80 to run my local server, but MacOS does not allow non-root users to bind to ports below 1024. To do so requires a additional steps.

$ brew services stop nginx

```sh
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

When I noticed my Eleventy site was already running there, I checked on Nginx:

$ brew services list
Name  Status     User  File
nginx error      geoff ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
$