laravel / valet

A more enjoyable local development experience for Mac.
https://laravel.com/docs/valet
MIT License
2.52k stars 697 forks source link

Massive log file being created #963

Closed mattkingshott closed 4 years ago

mattkingshott commented 4 years ago

Clear description of your problem

An issue with Valet (inc latest version) causes PHP FPM to log the following messages every few seconds:

[20-Jun-2020 10:09:36] NOTICE: [pool valet] 'user' directive is ignored when FPM is not running as root
[20-Jun-2020 10:09:36] NOTICE: [pool valet] 'user' directive is ignored when FPM is not running as root
[20-Jun-2020 10:09:36] NOTICE: [pool valet] 'group' directive is ignored when FPM is not running as root
[20-Jun-2020 10:09:36] NOTICE: [pool valet] 'group' directive is ignored when FPM is not running as root
[20-Jun-2020 10:09:36] ERROR: Another FPM instance seems to already listen on /Users/[user]/.config/valet/valet.sock
[20-Jun-2020 10:09:36] ERROR: Another FPM instance seems to already listen on /Users/[user]/.config/valet/valet.sock
[20-Jun-2020 10:09:36] ERROR: FPM initialization failed
[20-Jun-2020 10:09:36] ERROR: FPM initialization failed

Over time, this log file can become huge e.g. tens of gigabytes. I have determined that when this happens, it is possible to fix the problem by deleting the sock file:

rm /Users/[user]/.config/valet/valet.sock

A single message is then logged (without repeating):

[20-Jun-2020 10:12:07] NOTICE: [pool valet] 'user' directive is ignored when FPM is not running as root
[20-Jun-2020 10:12:07] NOTICE: [pool valet] 'user' directive is ignored when FPM is not running as root
[20-Jun-2020 10:12:07] NOTICE: [pool valet] 'group' directive is ignored when FPM is not running as root
[20-Jun-2020 10:12:07] NOTICE: [pool valet] 'group' directive is ignored when FPM is not running as root
[20-Jun-2020 10:12:07] NOTICE: fpm is running, pid 50543
[20-Jun-2020 10:12:07] NOTICE: ready to handle connections

Expected behavior

The messages first mentioned in this issue should only be logged once, if at all. Valet still works either way.

Steps to Reproduce

  1. In truth, I don't know why this happens, however I'm inclined to believe that it occurs following an update of PHP via home-brew.

Diagnosis

I'm running this after having fixed the problem as detailed above, so the details may not be relevant.

sw_vers
ProductName:   Mac OS X
ProductVersion: 10.15.5
BuildVersion:   19F101
valet --version
Laravel Valet 2.11.0
cat ~/.config/valet/config.json
{
    "tld": "test",
    "paths": [
        "/Users/matt/Documents/Apps",
        "/Users/matt/Documents/Clients"
    ]
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/valet": "^2.10",
        "friendsofphp/php-cs-fixer": "^2.16"
    }
}
composer global diagnose
Changed current directory to /Users/matt/.composer
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.10.7
PHP version: 7.4.7
PHP binary path: /usr/local/Cellar/php/7.4.7/bin/php
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020
composer global outdated
Changed current directory to /Users/matt/.composer
composer/semver   1.5.1  ~ 3.0.0  Semver library that offers utilities, version constraint parsing and validation.
php-cs-fixer/diff v1.3.0 ~ v2.0.1 sebastian/diff v2 backport support for PHP5.6
ls -al /etc/sudoers.d/
total 0
drwxr-xr-x   2 root  wheel    64 14 Mar 03:52 .
drwxr-xr-x  85 root  wheel  2720 13 Jun 08:13 ..
brew config
HOMEBREW_VERSION: 2.4.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: 28ed0801ed5807e176e62a3ba66e47ec867ec17d
Last commit: 9 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 4a0ac324980df95f21956e184acfe53d1206dd29
Core tap last commit: 9 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_MAKE_JOBS: 4
CPU: quad-core 64-bit kabylake
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Clang: 11.0 build 1103
Git: 2.24.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.5-x86_64
CLT: 1103.0.32.62
Xcode: N/A
brew services list
Name    Status  User Plist
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mysql   started matt /Users/matt/Library/LaunchAgents/homebrew.mxcl.mysql.plist
nginx   started root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php     error   root /Library/LaunchDaemons/homebrew.mxcl.php.plist
redis   started matt /Users/matt/Library/LaunchAgents/homebrew.mxcl.redis.plist
brew list --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
curl-openssl 7.70.0
dnsmasq 2.81
mysql 8.0.19_1
nginx 1.19.0
openssl@1.1 1.1.1g
php 7.4.7
brew outdated

php -v
PHP 7.4.7 (cli) (built: Jun 12 2020 00:04:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies
which -a php
/usr/local/bin/php
/usr/local/bin/php
/usr/bin/php
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.19.0
curl --version
curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets
php --ri curl
curl

cURL support => enabled
cURL Information => 7.70.0
Age => 6
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => No
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => Yes
SSL => Yes
SSPI => No
TLS-SRP => Yes
HTTP2 => Yes
GSSAPI => Yes
KERBEROS5 => Yes
UNIX_SOCKETS => Yes
PSL => No
HTTPS_PROXY => Yes
MULTI_SSL => No
BROTLI => Yes
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtmp, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => x86_64-apple-darwin19.4.0
SSL Version => OpenSSL/1.1.1g
ZLib Version => 1.2.11
libSSH Version => libssh2/1.9.0

Directive => Local Value => Master Value
curl.cainfo => no value => no value
~/.composer/vendor/laravel/valet/bin/ngrok version
ngrok version 2.3.35
ls -al ~/.ngrok2
ls: /Users/matt/.ngrok2: No such file or directory
brew info nginx
nginx: stable 1.19.0 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.19.0 (25 files, 2.1MB) *
  Poured from bottle on 2020-05-29 at 16:58:53
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb
==> Dependencies
Required: openssl@1.1, pcre
==> Options
--HEAD
    Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx
==> Analytics
install: 35,755 (30 days), 103,724 (90 days), 411,505 (365 days)
install-on-request: 34,682 (30 days), 100,609 (90 days), 396,331 (365 days)
build-error: 0 (30 days)
brew info php
php: stable 7.4.7 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/usr/local/Cellar/php/7.4.7 (520 files, 76.1MB) *
  Poured from bottle on 2020-06-18 at 20:40:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/php.rb
==> Dependencies
Build: httpd, pkg-config
Required: apr, apr-util, argon2, aspell, autoconf, curl-openssl, freetds, freetype, gettext, glib, gmp, icu4c, jpeg, libffi, libpng, libpq, libsodium, libzip, oniguruma, openldap, openssl@1.1, sqlite, tidy-html5, unixodbc, webp
==> Options
--HEAD
    Install HEAD version
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so

    
        SetHandler application/x-httpd-php
    

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.4/

To have launchd start php now and restart at login:
  brew services start php
Or, if you don't want/need a background service you can just run:
  php-fpm
==> Analytics
install: 51,737 (30 days), 151,918 (90 days), 514,458 (365 days)
install-on-request: 49,287 (30 days), 142,863 (90 days), 478,076 (365 days)
build-error: 0 (30 days)
brew info openssl
openssl@1.1: stable 1.1.1g (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/usr/local/Cellar/openssl@1.1/1.1.1g (8,059 files, 18MB)
  Poured from bottle on 2020-05-02 at 14:48:34
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl@1.1.rb
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Analytics
install: 677,150 (30 days), 2,406,749 (90 days), 5,972,526 (365 days)
install-on-request: 91,444 (30 days), 363,818 (90 days), 804,321 (365 days)
build-error: 0 (30 days)
openssl version -a
LibreSSL 2.8.3
built on: date not available
platform: information not available
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"
openssl ciphers
ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:GOST2012256-GOST89-GOST89:DHE-RSA-CAMELLIA256-SHA256:DHE-RSA-CAMELLIA256-SHA:GOST2001-GOST89-GOST89:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:CAMELLIA256-SHA256:CAMELLIA256-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:CAMELLIA128-SHA256:CAMELLIA128-SHA:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:RC4-SHA:RC4-MD5:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:DES-CBC3-SHA
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
which -a php-fpm
/usr/local/sbin/php-fpm
/usr/sbin/php-fpm
/usr/local/opt/php/sbin/php-fpm -v
PHP 7.4.7 (fpm-fcgi) (built: Jun 12 2020 00:04:22)
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies
sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/7.4/php-fpm.conf --test
[20-Jun-2020 10:16:29] NOTICE: configuration file /usr/local/etc/php/7.4/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--   1 matt  staff   657 20 Jun 10:09 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 matt  staff   543 20 Jun 10:09 homebrew.mxcl.mysql.plist
-rw-r--r--   1 matt  staff   571 20 Jun 10:09 homebrew.mxcl.nginx.plist
-rw-r--r--   1 matt  staff   628 20 Jun 10:09 homebrew.mxcl.php.plist
-rw-r--r--   1 matt  staff   823 20 Jun 10:09 homebrew.mxcl.redis.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   657 20 Jun 10:08 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   571 20 Jun 10:08 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   628 20 Jun 10:08 homebrew.mxcl.php.plist
drbyte commented 4 years ago

brew services list php error root /Library/LaunchDaemons/homebrew.mxcl.php.plist

ERROR: Another FPM instance seems to already listen on /Users/[user]/.config/valet/valet.sock

This situation is a result of you having Homebrew configured to run PHP twice: both as root and as non-root. That's why the logs are talking about "when FPM is not running as root" (and mentions [pool valet]) and "Another FPM instance seems to already listen on ... valet.sock":

NOTICE: [pool valet] 'user' directive is ignored when FPM is not running as root ERROR: Another FPM instance seems to already listen on /Users/[user]/.config/valet/valet.sock

It is also confirmed by having multiple launchd plists present for starting PHP under different users:

ls -al ~/Library/LaunchAgents -rw-r--r-- 1 matt staff 628 20 Jun 10:09 homebrew.mxcl.php.plist ls -al /Library/LaunchDaemons -rw-r--r-- 1 root admin 628 20 Jun 10:08 homebrew.mxcl.php.plist

Most likely at some point you manually started PHP using brew service start php (with/without sudo) instead of letting Valet handle it with "valet start".

The solution is a little cleanup:

brew services stop php
sudo brew services stop php
# The above commands should delete the plists but to be sure, the following removes them as well:
rm ~/Library/LaunchAgents/homebrew.mxcl.php.plist
sudo rm /Library/LaunchDaemons/homebrew.mxcl.php.plist
# now tell Valet to verify the configs are correct and restart things the way it wants it
valet install
# then reboot to be sure things are all restarting as desired
mattkingshott commented 4 years ago

Wow! Thanks so much for all of that. I’ll dig into it 👍🏻👍🏻

shakil-muntasir commented 4 years ago

Note than php, nginx, dnsmasq all should run as root.

Apply: brew services stop php brew services stop nginx brew services stop dnsmasq

DON'T start the following services manually, instead let valet install handle it.

if you decide to update the valet package from composer, simply run valet install everytime after the update. Hope that helps!

mattkingshott commented 4 years ago

I think my mistake in general was installing some of these things using brew rather than letting valet do it for me. In future, I'll just use brew to install other services e.g. mysql, redis etc.

It does beg the question, what is the process for upgrading php itself e.g. 7.3 to 7.4? Do you just do the upgrade within brew and then run a valet install?

shakil-muntasir commented 4 years ago

I think my mistake in general was installing some of these things using brew rather than letting valet do it for me. In future, I'll just use brew to install other services e.g. mysql, redis etc.

It does beg the question, what is the process for upgrading php itself e.g. 7.3 to 7.4? Do you just do the upgrade within brew and then run a valet install?

if you did not install a specific version like brew install php@7.3 and used brew install php then I believe brew upgrade is enough to upgrade from 7.3 to latest 7.4.x

mattkingshott commented 4 years ago

ah okay. Yes, that's the route I used. I just wondered if that process would create the issue itself.

shakil-muntasir commented 4 years ago

ah okay. Yes, that's the route I used. I just wondered if that process would create the issue itself.

The issue was due to how the php-fpm service was started. you started the php-fpm service as your user where valet needs it to run as root. Thus the conflict. Hope things are clear now. Good day!

mattkingshott commented 4 years ago

Right got it. Thanks!

drbyte commented 4 years ago

I think my mistake in general was installing some of these things using brew rather than letting valet do it for me. In future, I'll just use brew to install other services e.g. mysql, redis etc. It does beg the question, what is the process for upgrading php itself e.g. 7.3 to 7.4? Do you just do the upgrade within brew and then run a valet install?

if you did not install a specific version like brew install php@7.3 and used brew install php then I believe brew upgrade is enough to upgrade from 7.3 to latest 7.4.x

But if you are switching amongst PHP versions regularly, then using Valet to install the newest PHP version using valet use php@X.Y will minimize Homebrew/Valet's confusion that can occur when just brew install php happens (because in that case php is "the latest PHP version at the time", and not symlinked to X.Y).

I just wondered if that process would create the issue itself.

As @shakil-muntasir just mentioned, it's the "start" command that's the issue, not the "install" command.

mattkingshott commented 4 years ago

I'm always running the latest, so that's not a problem for me.

I'm pretty confident in this area now, so thank you to you both :)

danielbachhuber commented 2 years ago

Man, this continues to bite me all the time.

I think it happens after I run brew upgrade. I upgrade, whatever misconfiguration that happens runs for several days, and then I get an alert from my computer when my disk is almost full.

Has anyone found a reliable solution for not getting bit by this?

danielbachhuber commented 2 years ago

I just upgraded from v2.15.3 => v2.16.1, so I suppose v2.15.2 wasn't the fix for me.

Is there some series of valet commands I should run when I run brew upgrade, in order to prevent this from happening?

mattkingshott commented 2 years ago

I find that after doing brew upgrade, delete the plist files and then reinstall valet.