laravel / valet

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

Curl/Guzzle/Laravel Http Client can't communicate between Valet applications #983

Closed fylzero closed 3 years ago

fylzero commented 3 years ago

Clear description of your problem

When serving a front end and backend codebase in Valet, if you try to use the Laravel Http Client to simply make a call from the front end to the backend using the Valet test URL it errors out.

Expected behavior

The call should be successful.

Current behavior

The Http Client call returns the following error: cURL error 6: Could not resolve: whatever.test (Domain name not found) (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

Steps to Reproduce

  1. Stand up two copies of Laravel
  2. In app #1 (your API - myapi.test) create an API route with a callback that simply returns a string.
  3. In app #2 (your FE - myfe.test) create a web route that makes an Http client call to myapi.test/whateverendpointyoumade
  4. Bask in the warm glow of said error message.

Output of these steps

See current behavior section for the returned error.

Possible solution

Still looking.

Diagnosis

sw_vers
ProductName:   Mac OS X
ProductVersion: 10.15.6
BuildVersion:   19G2021
valet --version
Laravel Valet 2.11.0
cat ~/.config/valet/config.json
{
    "tld": "test",
    "paths": [
        "/Users/ptheobald/code/valet"
    ]
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/installer": "^3.1",
        "laravel/valet": "^2.11"
    }
}
composer global diagnose
Changed current directory to /Users/ptheobald/.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 rate limit: 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: You are not running the latest stable version, run `composer self-update` to update (1.10.8 => 1.10.13)
Composer version: 1.10.8
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/ptheobald/.composer
guzzlehttp/guzzle                6.5.5   ~ 7.1.1   Guzzle is a PHP HTTP client library
guzzlehttp/promises              v1.3.1  ! 1.4.0   Guzzle promises library
guzzlehttp/psr7                  1.6.1   ! 1.7.0   PSR-7 message implementation that also provides common utility methods
illuminate/container             v7.17.2 ~ v8.7.1  The Illuminate Container package.
illuminate/contracts             v7.17.2 ~ v8.7.1  The Illuminate Contracts package.
laravel/installer                v3.1.0  ~ v4.0.5  Laravel application installer.
php-di/invoker                   2.0.0   ! 2.1.0   Generic and extensible callable invoker
symfony/console                  v5.1.2  ! v5.1.6  Symfony Console Component
symfony/filesystem               v5.1.2  ! v5.1.6  Symfony Filesystem Component
symfony/polyfill-ctype           v1.17.1 ! v1.18.1 Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme   v1.17.1 ! v1.18.1 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn        v1.17.1 ! v1.18.1 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer v1.17.1 ! v1.18.1 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring        v1.17.1 ! v1.18.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72           v1.17.0 ! v1.18.1 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73           v1.17.1 ! v1.18.1 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80           v1.17.1 ! v1.18.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/process                  v5.1.2  ! v5.1.6  Symfony Process Component
symfony/service-contracts        v2.1.2  ! v2.2.0  Generic abstractions related to writing services
symfony/string                   v5.1.2  ! v5.1.6  Symfony String component
symfony/var-dumper               v5.1.2  ! v5.1.6  Symfony mechanism for exploring and dumping PHP variables
tightenco/collect                v7.12.0 ~ v8.0.4  Collect - Illuminate Collections as a separate package.
ls -al /etc/sudoers.d/
total 0
drwxr-xr-x   2 root  wheel    64 Apr 17 16:52 .
drwxr-xr-x  85 root  wheel  2720 Sep 23 09:52 ..
brew config
HOMEBREW_VERSION: 2.5.2
ORIGIN: https://github.com/Homebrew/brew
HEAD: cd4a3c0588abb82d916bc8558f4c157e951d449d
Last commit: 10 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: fb03d699a751a184fae2382943fe3a3960023469
Core tap last commit: 3 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: dodeca-core 64-bit kabylake
Clang: 12.0 build 1200
Git: 2.24.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.6-x86_64
CLT: 12.0.0.0.1.1599194153
Xcode: N/A
brew services list
Name      Status  User      Plist
dnsmasq   started root      /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mysql@5.7 started ptheobald /Users/ptheobald/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx     started root      /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php       started root      /Library/LaunchDaemons/homebrew.mxcl.php.plist
brew list --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
curl-openssl 7.71.0
dnsmasq 2.81
mysql@5.7 5.7.29
nginx 1.19.0
openssl@1.1 1.1.1g
php 7.4.7
brew outdated
brotli
c-ares
curl-openssl
dnsmasq
freetds
gdbm
gettext
glib
libevent
libidn
libpq
libzip
mysql@5.7
nghttp2
nginx
node
openldap
php
python@3.8
sqlite
unixodbc
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/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.71.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.5.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/ptheobald/.ngrok2: No such file or directory
brew info nginx
nginx: stable 1.19.2 (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-06-25 at 19:38:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> 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: 29,235 (30 days), 102,644 (90 days), 405,018 (365 days)
install-on-request: 28,880 (30 days), 100,723 (90 days), 393,287 (365 days)
build-error: 0 (30 days)
brew info php
php: stable 7.4.10 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/usr/local/Cellar/php/7.4.7 (519 files, 76.1MB) *
  Poured from bottle on 2020-06-25 at 19:33:52
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/php.rb
License: PHP-3.01
==> Dependencies
Build: httpd, pkg-config
Required: apr, apr-util, argon2, aspell, autoconf, curl-openssl, freetds, gd, gettext, glib, gmp, icu4c, krb5, libffi, libpq, libsodium, libzip, oniguruma, openldap, openssl@1.1, pcre2, sqlite, tidy-html5, unixodbc
==> 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: 50,595 (30 days), 157,371 (90 days), 564,644 (365 days)
install-on-request: 49,521 (30 days), 153,549 (90 days), 534,130 (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-06-25 at 17:54:53
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb
License: OpenSSL
==> 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: 497,976 (30 days), 1,672,648 (90 days), 7,013,752 (365 days)
install-on-request: 61,767 (30 days), 196,275 (90 days), 912,276 (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
[01-Oct-2020 12:26:10] 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 ptheobald  staff   551 Jun 25 19:35 homebrew.mxcl.mysql@5.7.plist
-rw-r--r--   1 ptheobald  staff   628 Jun 25 19:34 homebrew.mxcl.php.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   657 Jun 25 19:38 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   571 Oct  1 10:07 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   628 Jun 25 19:38 homebrew.mxcl.php.plist
drbyte commented 3 years ago

The Http Client call returns the following error: cURL error 6: Could not resolve: whatever.test (Domain name not found)

Given the error message is saying that CURL can't resolve the domain name it seems like that's the root issue.

Perhaps fixing that is as simple as setting your Mac's network settings to use 127.0.0.1 as a primary resolver in your DNS providers list?

fylzero commented 3 years ago

@drbyte I can get it working by adding 127.0.0.1 myapi.test into /etc/hosts but would imagine this should be able to, and would be intended to, work without doing that. Namely as one of the first sentences in the readme of this project is "No Vagrant, no /etc/hosts file." 😃

I've also seen other solutions where people are re-installing or updating curl-openssl: https://stackoverflow.com/questions/54688451/curl-laravel-valet-dnsmasq-not-working

Could this be a dependency issue with Valet?

drbyte commented 3 years ago

I've also seen other solutions where people are re-installing or updating curl-openssl:

It could be that your own CURL/openssl components are not working correctly.

(And it's worth updating them (updating all your homebrew stuff regularly)).

But the reason I mention adding localhost to your DNS resolvers is that Valet relies on dnsmasq to do the resolving of .test domains, and if your CURL install is defaulting to some other lookup source first then it won't get what dnsmasq is expected to provide for you.

My point, which you've confirmed by mentioning that the hosts file edits work, is that your CURL isn't using dnsmasq for its name resolution.

The simplest way to fix that is to tell your Mac to use 127.0.0.1 as the first (or only) DNS provider. System Preferences -> Network -> Advanced -> DNS

dns127-0-0-1
fylzero commented 3 years ago

I wound up following the advice in the StackOverflow link...

brew uninstall curl-openssl --ignore-dependencies
brew services restart php
valet restart

I guess that makes this a cURL version issue.