Laravel Valet 502 Bad Gate Way nginx/1.15.7

Laravel Valet 502 Bad Gate Way nginx/1.15.7

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Laravel Valet 502 Bad Gate Way nginx/1.15.7

Encountering a 502 Bad Gateway error on a local stack powered by Laravel Valet usually points to a communication breakdown between your web server (NGINX) and the PHP FastCGI Process Manager (PHP-FPM). When you see nginx/1.15.7 in the response header, it confirms that NGINX is receiving an invalid or incomplete response from the backend. While this often suggests a misconfigured reverse proxy, in many local development scenarios involving Valet, the root cause lies deeper in the PHP configuration files themselves.

The specific error trace provided in your logs highlights a critical missing file: /usr/local/etc/php/7.3/php-fpm.d/www.conf. The Valet\Filesystem class attempts to read this configuration to inject site-specific settings, but the stream opens as "No such file or directory." This isn't just a cosmetic warning; it breaks the initialization sequence for PHP-FPM. Without a valid www.conf, NGINX cannot successfully hand off requests to PHP, resulting in that persistent 502 error.

The standard workaround found on many online gists often involves manually creating the missing file or modifying existing paths. However, blindly copying configuration files from the system default location can lead to further instability if those defaults don't match the specific version of PHP you installed via Homebrew or Laravel's installer. The core issue here is that Valet expects a certain directory structure under /usr/local/etc/php/ which may have been inadvertently cleared or misaligned during a previous valet install or manual cleanup attempt.

To resolve this, you need to ensure the PHP-FPM configuration directory exists and contains the expected files for your specific PHP version. First, verify the existence of the directory structure:

ls -la /usr/local/etc/php/7.3/php-fpm.d/

If the directory is empty or missing, you must recreate it. You can do this by creating the directory manually and then populating it with a valid www.conf. A safe approach is to copy the default configuration from the system's PHP installation location (usually found in /opt/homebrew/opt/php@7.3/etc/ on Apple Silicon or /usr/local/opt/php@7.3/etc/ on Intel Macs) into the Valet expected path, adjusting paths relative to your home directory if necessary.

mkdir -p /usr/local/etc/php/7.3/php-fpm.d
# Copy the default configuration from Homebrew's PHP installation
cp /opt/homebrew/opt/php@7.3/etc/php-fpm.conf.default /usr/local/etc/php/7.3/php-fpm.d/www.conf

Note: Adjust the source path (/opt/homebrew/...) based on your specific Homebrew prefix, which you can find using brew info php.

Once the file is in place, you must ensure that the PHP-FPM service is actually running. The error log often fails to surface because the process isn't listening on the socket NGINX expects. Restarting the Valet services forces a re-evaluation of these configurations:

valet install
valet stop
valet start

After restarting, visit your site again. If the 502 error persists, check the NGINX error log at /usr/local/var/log/nginx/error.log. You might find messages indicating that PHP-FPM is refusing connections due to incorrect user or group directives in the newly created www.conf, often because it defaults to system users like www-data which don't exist on macOS. Ensure these are set to your actual system user (e.g., daemon) or your specific username.

Finally, if you have recently updated PHP versions or switched between different PHP runtimes, the versioned directory structure (/usr/local/etc/php/7.3/) might be out of sync with the active runtime. In such cases, using Laravel Valet's built-in version management is safer than manually editing system paths. Run valet use php@7.3 to ensure the correct binary and configuration paths are aligned before restarting the services.

By restoring the missing www.conf and ensuring the PHP-FPM daemon is running with the correct permissions, you bridge the gap between NGINX and PHP, eliminating the 502 Bad Gateway error and restoring normal development flow.

Our network