🖤 Black Friday / Cyber Monday: 20% off Stratos Pro with code BFCM20 — Founder Lifetime $89 $71.20 once (ends Dec 7). Claim Deal →
BFCM20 · 20% Off⚡ New in v1.7.2: 1-Click MCP Server for Cursor & Claude Code — Lock in the $89 → $71.20 Founder Lifetime License with code BFCM20 (Save $207+/yr vs Herd Pro)Claim Founder Tier →
Stratosv1.7.2
Troubleshooting & Fixes• 3 min read

How to Fix Laravel Herd & Valet 502 Bad Gateway (Nginx) on macOS

Instant copy-paste terminal commands to fix Laravel Herd 502 Bad Gateway, broken PHP-FPM Unix domain sockets, crashed daemons, and Nginx upstream errors on macOS.


Why Does Nginx Return 502 Bad Gateway?

In macOS local development environments (like Laravel Valet, Laravel Herd, or custom Nginx setups), a 502 Bad Gateway error almost always means Nginx is running properly, but the upstream FastCGI process (PHP-FPM) has crashed, failed to spawn its Unix domain socket, or has mismatched user permissions.

💡 Instant Fix for Stratos Users: Open the Stratos menu bar icon, toggle PHP-FPM off and on, or click Site Doctor → Fix Permissions & Sockets. Stratos monitors Unix sockets automatically and cleans stale PIDs on launch.

Step 1: Check If PHP-FPM Is Running

Open Terminal on your Mac and verify whether any PHP-FPM processes are active:

ps aux | grep php-fpm

If the command only returns the grep line itself, your PHP-FPM daemon has crashed or failed to start.

Step 2: Kill Stuck Orphan Processes & Clear Stale Sockets

Often, an unclean macOS reboot or app crash leaves behind a dead Unix socket file or zombie PHP processes holding port 9000 or the socket path:

# Kill any hung PHP-FPM processes
sudo killall php-fpm 2>/dev/null || true

# For Laravel Valet: remove stale socket and restart
rm -f ~/.config/valet/valet.sock
valet restart

# For Laravel Herd: restart via CLI
herd restart

Step 3: Inspect Nginx Error Logs for the Root Cause

If restarting doesn't fix the 502 error, check the exact error Nginx received from the upstream socket:

# For Valet
tail -n 30 ~/.config/valet/Log/nginx-error.log

# For Herd
tail -n 30 ~/Library/Application Support/Herd/Log/nginx-error.log

# For Stratos
tail -n 30 ~/Library/Application Support/Stratos/logs/nginx-error.log

Common log entries and their solutions:

  • connect() to unix:.../php-fpm.sock failed (2: No such file or directory): PHP-FPM failed to boot. Reinstall the active PHP version or check php-fpm.conf for syntax errors.
  • Permission denied while connecting to upstream: Socket file was created by root instead of your local user. Run sudo chown $(whoami):staff ~/.config/valet/*.sock.
  • upstream sent too big header while reading response header: Increase fastcgi_buffer_size to 128k in your Nginx config.

The Permanent Solution: Switch to Stratos

Tired of debugging Homebrew PHP sockets, port 9000 collisions, and random 502 errors after every macOS Sequoia update? Stratos isolates each PHP version (8.1 through 8.5) into dedicated, sandboxed Unix sockets with automated health checks, stale PID cleanup, and instant 1-click restarts.

Download Stratos Free for macOS →

🖤 BFCM20 · 20% OFF THROUGH DEC 7, 2026

Replace $296+/yr of macOS Dev Subscriptions with Stratos

Start free forever with native Nginx, PHP 8.1–8.5, .test HTTPS, Xdebug 3, and read-only MCP schema tools—or lock in the Founder Lifetime license (3 Macs) for $71.20 (reg. $89) with code BFCM20.