If you face “Error: Another FPM Instance…” in your Laravel Valet php-fpm logs, as per list below, here is one of the fix you can do to ensure these are not going on forever. if you run the code below in your console (Terminal, iTerm, Warp), you can see the errors related to php-fpm. This is post focus on the PHP installed using Homebrew.
After removing, uninstalling the PHP packages I installed using homebrew, the errors keep on showing up. Even though I stopped the “php” service. Apparently, there were config issue when old packages seem to be configured to create a socket on latest version of PHP, instead of its own version.
Error: Another FPM Instance
valet logs -f php-fpm
And it might shows these errors, which might be more than just what was sampled below. It could be multiple version of sockets, with the name normat “valetXX.sock”. You should be able to see many of the “Error: Another FPM Instance…” in your log.
...
[21-May-2023 11:35:55] ERROR: Another FPM instance seems to already listen on /Users/username/.config/valet/valet82.sock
[21-May-2023 11:35:55] ERROR: Another FPM instance seems to already listen on /Users/username/.config/valet/valet82.sock
[21-May-2023 11:35:55] ERROR: FPM initialization failed
[21-May-2023 11:35:55] ERROR: FPM initialization failed
...
First, go to the php config folder(s). You might have few of them, such as 7.4, 8.0, 8.1, 8.2, etc. You must go through each of them to ensure they have the correct config for socket.
cd /opt/homebrew/etc/php/
ls -lh
drwxr-xr-x@ 10 username admin 320B May 21 09:18 8.0
drwxr-xr-x@ 10 username admin 320B May 21 09:19 8.1
drwxr-xr-x@ 8 username admin 256B May 21 11:23 8.2
cd 8.0/php-fpm.d/
ls -lh
-rw-r--r--@ 1 username admin 722B May 21 11:26 valet-fpm.conf
-rw-r--r--@ 1 username admin 20K May 21 09:18 www.conf.default
nano valet-fpm.conf
In the editing mode using nano
, you can see certain line as below in file “valet-fpm.conf”:
; FPM pool configuration for Valet
[valet]
user = username
group = staff
listen = /Users/username/.config/valet/valet82.sock
listen.owner = username
listen.group = staff
listen.mode = 0777
;; When uncommented, the following values will take precedence over settings declared elsewhere
;php_admin_value[memory_limit] = 512M
;php_admin_value[upload_max_filesize] = 128M
;php_admin_value[post_max_size] = 128M
;php_admin_value[error_log] = /Users/username/.config/valet/Log/php-fpm.log
;php_admin_flag[log_errors] = on
;; Note: increasing these values will increase the demand on your CPU and RAM resources
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
Focus on line number 6, you can see that this file defines the php-fpm socket for the specific version [email protected]. You can look into this file, in each version of the PHP installed. The correction socket file name should be “valet80.sock” instead of “valet82.sock” because this file is in /opt/homebrew/etc/php/8.0/php-fpm.d/valet-fpm.conf
.
Next, make sure you stop all running php with user permission in homebrew
. Use the command below:
brew services stop php
brew services stop [email protected]
brew services stop [email protected]
brew services stop [email protected]
Then, restart them using valet restart
or command with sudo
as per below:
sudo brew services start php
sudo brew services start [email protected]
sudo brew services start [email protected]
sudo brew services start [email protected]
Then, verify those php-fpm instances are running with root
permission space:
sudo brew services list
Name Status User File
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
httpd none root
mailhog none root
mariadb none root
nginx started root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
[email protected] started root /Library/LaunchDaemons/[email protected]
[email protected] started root /Library/LaunchDaemons/[email protected]
redis none root
unbound none root
Hopefully that solves the issue of multiple request to initiate start php-fpm services.
You can also use PHP Monitor to help restart those homebrew services.