'Valet is not working with php.8 Nginx return Bad Gateway

Hi I have try to update php to 8.0 but always there a problem with valet to read the new version and I try to solve it without specific instructions but this time is stucked I will abbreviated my question and print valet diagnose

valet --version

Laravel Valet 2.14.1

brew services list

dnsmasq    error   root          /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
httpd      stopped
mysql      started mohammedalama /usr/local/opt/mysql/homebrew.mxcl.mysql.plist
nginx      error   root          /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php        error   root          /Library/LaunchDaemons/homebrew.mxcl.php.plist
redis      started mohammedalama /usr/local/opt/redis/homebrew.mxcl.redis.plist
supervisor started mohammedalama /usr/local/opt/supervisor/homebrew.mxcl.supervisor.plist

brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"

dnsmasq 2.84
mysql 8.0.19
nginx 1.19.8
openssl@1.1 1.1.1k
php 8.0.3

php -v

PHP 8.0.3 (cli) (built: Mar  4 2021 20:45:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies

php --ini

Configuration File (php.ini) Path: /usr/local/etc/php/8.0
Loaded Configuration File:         (none)
Scan for additional .ini files in: /usr/local/etc/php/8.0/conf.d
Additional .ini files parsed:      /usr/local/etc/php/8.0/conf.d/error_log.ini,
/usr/local/etc/php/8.0/conf.d/php-memory-limits.ini

nginx -v

nginx version: nginx/1.19.8

sudo nginx -t

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/8.0/php-fpm.conf --test

[04-Apr-2021 11:20:10] ERROR: failed to open configuration file '/usr/local/etc/php/8.0/php-fpm.conf': No such file or directory (2)
[04-Apr-2021 11:20:10] ERROR: failed to load configuration file '/usr/local/etc/php/8.0/php-fpm.conf'
[04-Apr-2021 11:20:10] ERROR: FPM initialization failed

ls -al /Library/LaunchAgents | grep homebrew

output is empty

ls -al /Library/LaunchDaemons | grep homebrew

-rw-r--r--   1 root  admin   657 Apr  4 11:03 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   571 Apr  4 11:03 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   628 Apr  4 11:03 homebrew.mxcl.php.plis

ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

output is empty


Solution 1:[1]

You are using Mac OS right? sudo brew services list shows php error root, so it seems like php-fpm is failing to start.
I had a similar problem, but I found this github issue: https://github.com/laravel/valet/issues/269

At first, I changed php version of valet by:

$ valet use php@8.0
$ sudo brew services stop php
$ brew services stop php
$ valet install

Then, following the comment of yratof of the github issue, I copied /usr/local/etc/php/8.0/php-fpm.d/valet-fpm.conf to /usr/local/etc/php/8.0/php-fpm.conf. Then run:

$ valet install
$ valet restart

Then check the php's status again by

$ sudo brew services list

If php's error is removed, I think valet will work properly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1