laravel / valet

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

Valet not starting on boot after adding custom nginx proxy directive #837

Closed gldrenthe89 closed 4 years ago

gldrenthe89 commented 4 years ago

The Valet deamon doesn't start on boot. I have to manually start is everytime using -> valet start

I allready have reinstalled valet but didn't do the trick

drbyte commented 4 years ago

@gldrenthe89 what's the output of the following, on a reboot, before running valet start?

brew services list
brew doctor

Additional information which would also be helpful is the output of the following:

sw_vers
valet --version
cat ~/.config/valet/config.json
ls -al /etc/sudoers.d/
openssl version -a
openssl ciphers
php -v
which php
which -a php
nginx -v
curl --version
php --ri curl
brew config
brew doctor
brew info openssl
brew info nginx
brew info php
~/.composer/vendor/laravel/valet/bin/ngrok version
ls -al ~/.ngrok2
sudo nginx -t
gldrenthe89 commented 4 years ago

Hi i have done every command requested and here is the output:

`➜ ~ brew services list Name Status User Plist dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist mysql started geertlucasdrenthe /Users/geertlucasdrenthe/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 geertlucasdrenthe /Users/geertlucasdrenthe/Library/LaunchAgents/homebrew.mxcl.redis.plist ➜ ~

➜ ~ brew doctor Your system is ready to brew. ➜ ~

➜ ~ sw_vers ProductName: Mac OS X ProductVersion: 10.15.1 BuildVersion: 19B88 ➜ ~

➜ ~ valet --version Laravel Valet 2.5.2 ➜ ~

➜ ~ cat ~/.config/valet/config.json { "tld": "test", "paths": [ "/Users/geertlucasdrenthe/Development/Sites" ] } ➜ ~

➜ ~ ls -al /etc/sudoers.d/ total 0 drwxr-xr-x 2 root wheel 64 24 aug 01:37 . drwxr-xr-x 87 root wheel 2784 3 dec 09:05 .. ➜ ~

➜ ~ 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 ➜ ~

➜ ~ php -v PHP 7.4.0 (cli) (built: Nov 29 2019 16:18:44) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies ➜ ~

➜ ~ which php /usr/local/bin/php ➜ ~

➜ ~ which -a php /usr/local/bin/php /usr/bin/php ➜ ~

➜ ~ nginx -v nginx version: nginx/1.17.3 ➜ ~

➜ ~ 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.67.0 Age => 5 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.0.0 SSL Version => OpenSSL/1.1.1d ZLib Version => 1.2.11 libSSH Version => libssh2/1.9.0

Directive => Local Value => Master Value curl.cainfo => no value => no value ➜ ~

➜ ~ brew config HOMEBREW_VERSION: 2.2.0 ORIGIN: https://github.com/Homebrew/brew HEAD: 7d7de295dfbc5e581106e2b1f674496b5e25a773 Last commit: 6 days ago Core tap ORIGIN: https://github.com/Homebrew/homebrew-core Core tap HEAD: ab840d654f4abc8b3c8bbce20f06eb7b20735aab Core tap last commit: 5 hours ago HOMEBREW_PREFIX: /usr/local CPU: octa-core 64-bit kabylake Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby Clang: 11.0 build 1100 Git: 2.21.0 => /Applications/Xcode.app/Contents/Developer/usr/bin/git Curl: 7.64.1 => /usr/bin/curl macOS: 10.15.1-x86_64 CLT: 11.2.0.0.1.1571444319 Xcode: 11.2.1 CLT headers: 11.2.0.0.1.1571444319 ➜ ~

➜ ~ brew info openssl openssl@1.1: stable 1.1.1d (bottled) [keg-only] Cryptography and SSL/TLS Toolkit https://openssl.org/ /usr/local/Cellar/openssl@1.1/1.1.1d (7,983 files, 17.9MB) Poured from bottle on 2019-09-26 at 09:18:41 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 openssl/libressl is provided by macOS so don't link an incompatible version.

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"

For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> Analytics install: 499,588 (30 days), 1,828,393 (90 days), 2,362,918 (365 days) install-on-request: 50,960 (30 days), 147,946 (90 days), 421,371 (365 days) build-error: 0 (30 days) ➜ ~

➜ ~ brew info nginx nginx: stable 1.17.3 (bottled), HEAD HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server https://nginx.org/ /usr/local/Cellar/nginx/1.17.3_1 (25 files, 2MB) * Poured from bottle on 2019-09-06 at 15:30:23 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: 26,101 (30 days), 81,761 (90 days), 402,893 (365 days) install-on-request: 25,519 (30 days), 79,386 (90 days), 382,407 (365 days) build-error: 0 (30 days) ➜ ~

➜ ~ brew info php php: stable 7.4.0 (bottled) General-purpose scripting language https://www.php.net/ /usr/local/Cellar/php/7.4.0 (517 files, 75.9MB) * Poured from bottle on 2019-12-03 at 09:11:30 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 ✔ ==> 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

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

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: 46,925 (30 days), 133,330 (90 days), 462,271 (365 days) install-on-request: 43,890 (30 days), 123,995 (90 days), 422,187 (365 days) build-error: 0 (30 days) ➜ ~

➜ ~ ~/.composer/vendor/laravel/valet/bin/ngrok version ngrok version 2.3.34 ➜ ~

➜ ~ ls -al ~/.ngrok2 ls: /Users/geertlucasdrenthe/.ngrok2: No such file or directory ➜ ~

➜ ~ 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 ➜ ~

`

drbyte commented 4 years ago

php error root /Library/LaunchDaemons/homebrew.mxcl.php.plist

It's interesting that that says error, instead of started or stopped

drbyte commented 4 years ago

What happens when you run: launchctl load /Library/LaunchDaemons/homebrew.mxcl.php.plist I'm curious whether it outputs any messages.

Additionally, looking into logs may be revealing.

I'm guessing there may be some php.ini or other configuration problems. You could try the following, which removes the php configs to allow for a reset, then reinstall php and reconfigure it for Valet:

mv -rf /usr/local/etc/php/7.4 /usr/local/etc/php/7.4-bad
brew reinstall php --force
valet install
gldrenthe89 commented 4 years ago

result:

➜ ~ launchctl load ~/Library/LaunchDaemons/homebrew.mxcl.php.plist /Users/geertlucasdrenthe/Library/LaunchDaemons/homebrew.mxcl.php.plist: No such file or directory ➜ ~

drbyte commented 4 years ago

Okay, then let's do the other steps, since it seems your PHP isn't installed completely

drbyte commented 4 years ago

Oh wait: I made a typo. (I think the ~ should have been skipped) Try: launchctl load /Library/LaunchDaemons/homebrew.mxcl.php.plist

gldrenthe89 commented 4 years ago

omg dude you are the man. forcing that reinstall of php did the trick

how simple a solution can be

but to be complete here is the output

➜ ~ launchctl load /Library/LaunchDaemons/homebrew.mxcl.php.plist /Library/LaunchDaemons/homebrew.mxcl.php.plist: service already loaded ➜ ~

drbyte commented 4 years ago

Cool! I'm glad that solved it. Sometimes the solution is simple once enough data about it is revealed.

I'd never seen that error status before though, so that's new!

If Valet is working properly now, please click the Close button below.

gldrenthe89 commented 4 years ago

closing the issue.

error code was: php error root /Library/LaunchDaemons/homebrew.mxcl.php.plist

solution in my case mv -rf /usr/local/etc/php/7.4 /usr/local/etc/php/7.4-bad brew reinstall php --force valet install

drbyte commented 4 years ago

You can also remove the php 7.4-bad directory, unless you'd customized anything in there yourself. rm -rf /usr/local/etc/php/7.4-bad

gldrenthe89 commented 4 years ago

Too bad. after a reboot it stopped working again. have to manually start it.

gldrenthe89 commented 4 years ago

result of: launchctl load /Library/LaunchDaemons/homebrew.mxcl.php.plist

➜ ~ launchctl load /Library/LaunchDaemons/homebrew.mxcl.php.plist /Library/LaunchDaemons/homebrew.mxcl.php.plist: service already loaded ➜ ~

result of brew service list:

➜ ~ brew services list

Name    Status  User              Plist
dnsmasq started root              /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mysql   started geertlucasdrenthe /Users/geertlucasdrenthe/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 geertlucasdrenthe /Users/geertlucasdrenthe/Library/LaunchAgents/homebrew.mxcl.redis.plist

➜ ~

and this is after valet start.

before i started valet it gave me this output

➜  ~ brew services list 
Name    Status  User              Plist
dnsmasq started root              /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mysql   started geertlucasdrenthe /Users/geertlucasdrenthe/Library/LaunchAgents/homebrew.mxcl.mysql.plist
nginx   started root              /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php     started root              /Library/LaunchDaemons/homebrew.mxcl.php.plist
redis   started geertlucasdrenthe /Users/geertlucasdrenthe/Library/LaunchAgents/homebrew.mxcl.redis.plist
drbyte commented 4 years ago

Okay, if it's showing error then that suggests PHP is giving an undesired return code.

Perhaps the core PHP log file will reveal some information? /usr/local/var/log/php-fpm.log (consider using tail as the file may be very large. You could also simply delete the file and it will regenerate)

gldrenthe89 commented 4 years ago

her is the result

[06-Dec-2019 11:01:44] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:01:44] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:01:44] ERROR: FPM initialization failed
[06-Dec-2019 11:01:44] ERROR: FPM initialization failed
[06-Dec-2019 11:01:52] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:01:52] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:01:52] ERROR: FPM initialization failed
[06-Dec-2019 11:01:52] ERROR: FPM initialization failed
[06-Dec-2019 11:02:02] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:02:02] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:02:02] ERROR: FPM initialization failed
[06-Dec-2019 11:02:02] ERROR: FPM initialization failed
[06-Dec-2019 11:02:12] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:02:12] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:02:12] ERROR: FPM initialization failed
[06-Dec-2019 11:02:12] ERROR: FPM initialization failed
[06-Dec-2019 11:02:22] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:02:22] ERROR: Another FPM instance seems to already listen on /Users/geertlucasdrenthe/.config/valet/valet.sock
[06-Dec-2019 11:02:22] ERROR: FPM initialization failed
[06-Dec-2019 11:02:22] ERROR: FPM initialization failed
gldrenthe89 commented 4 years ago

doesn't seem good.

gldrenthe89 commented 4 years ago

i'v tried the following also:

➜  ~ brew services cleanup
All user-space services OK, nothing cleaned...
➜  ~ sudo brew services cleanup
Password:
All root services OK, nothing cleaned...
➜  ~ 
gldrenthe89 commented 4 years ago

after searching a bit i tried this:

https://github.com/laravel/valet/issues/650#issuecomment-454794916

result in log file is different now en after a reboot valet starts. i wil try more reboots to be shure

[06-Dec-2019 11:15:33] NOTICE: fpm is running, pid 129
[06-Dec-2019 11:15:33] NOTICE: ready to handle connections
[06-Dec-2019 11:17:45] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
[06-Dec-2019 11:17:54] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
gldrenthe89 commented 4 years ago

i've found out something. valet does not start when i use custom nginx configuration on 1 site.

i change the nginx config to look for images on a external server.

location ~*  \.(jpg|jpeg|png|gif|pdf|ico)$ {
        try_files $uri @production;
        expires 24h;
    }

    location @production {
        resolver 8.8.8.8;
        proxy_pass (some_url);
    }
gldrenthe89 commented 4 years ago

brew services are al starten and manually restarting al services indepently did start a thing.

only valet start does the trick

drbyte commented 4 years ago
  1. Does removal of that custom nginx config allow things to start properly?

  2. Valet 2.6 released today (to get it, must run composer global update), and contains a full uninstall capability: valet uninstall --force, which will aggressively remove all nginx configs, PHP configs, and dnsmasq configs, and the homebrew apps for those. You can then run valet install for a fresh clean install. It'd be helpful to know if things start correctly after that. And then you can start experimenting with your nginx custom directives for specific sites.

gldrenthe89 commented 4 years ago

i did what you askes above.

After mulitple reboot after the reinstall everything worked fine.

but when is tried editing the nginx config and added

location ~*  \.(jpg|jpeg|png|gif|pdf|ico)$ {
        try_files $uri @production;
        expires 24h;
    }

    location @production {
        resolver 8.8.8.8;
        proxy_pass (some_url);
    }

it stopped form starting on boot.

gldrenthe89 commented 4 years ago

when i remove the lines of code from the custom nginx config the is works fine

I used the valet secure command to create the nginx file in the config folder. this file i then edit.

I need this extra config so the images are loaded from production environment.

The config works fine when i start valet myself

drbyte commented 4 years ago

@gldrenthe89

gldrenthe89 commented 4 years ago

@gldrenthe89

  • is this still a problem? especially with latest Valet (composer global update)
  • if yes, can you report which service is currently not starting properly at boot? Is it php or nginx? (ie: brew services list after bootup, before manually starting things)

Problem still there. When nginx config had been edited like above it doesnt start anymore. Cant work without above nginx config so i think this will be a problem for me

drbyte commented 4 years ago

If nginx won't start with that custom config, then it'd be helpful to know if it's logging anything about it. /usr/local/var/log/nginx/error.log

Also, I'm curious whether there are file-permissions issues on the nginx config you've edited. (On boot, nginx starts as root, so it shouldn't have problems accessing files for any user, but we're looking at edge-cases here, so this comes to mind.)

gldrenthe89 commented 4 years ago

If nginx won't start with that custom config, then it'd be helpful to know if it's logging anything about it. /usr/local/var/log/nginx/error.log

Also, I'm curious whether there are file-permissions issues on the nginx config you've edited. (On boot, nginx starts as root, so it shouldn't have problems accessing files for any user, but we're looking at edge-cases here, so this comes to mind.)

After reviewing the log file i found out that somehow the URL wasn't resolved on first attemp of starting the nginx services. It is weird that manually starting Valet doesn't give this error. I have changed the url to a direct ip adres and after multiple reboots and tests i can say that this solves the problem. Looks like valet/nginx is started on boot just before the dns services are working. even when specifically telling nginx to use 8.8.8.8.

I hope i can keep this closed.

Many thanks for al the contributers in helping me out with this

drbyte commented 4 years ago

@gldrenthe89 Thanks for posting back. Do you mind updating the title of this issue to add mention of custom proxy settings? This just helps people filter more quickly if they have a similar (or non-similar) issue.

Maybe something like Valet not starting on boot after adding custom proxy directive ?