Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valet fails to find valid .valetphprc #1336

Closed
mikeybinns opened this issue Jan 10, 2023 · 24 comments · Fixed by #1361
Closed

Valet fails to find valid .valetphprc #1336

mikeybinns opened this issue Jan 10, 2023 · 24 comments · Fixed by #1361

Comments

@mikeybinns
Copy link

Description:

Both of the valet use and valet isolate command are failing to find the valid .valetphprc file in the project root.
I have tested with my colleague this, and it fails on both of our work macs with the following setup:
My work mac (fails)
valet version 3.2.2
Composer version 2.3.1 and 2.5.1 (tried both)
Arm mac on Ventura 13.1

His work mac (fails)
valet version 3.1.6
Composer version 2.5.1
Arm mac on Monterey 12.6

His personal mac (works)
valet version 3.1.6
Composer version 2.3.1
Intel mac on Ventura 13.1

Steps To Reproduce:

Update to v3.2.2
Navigate in terminal to project root
create .valetphprc and use the contents [email protected]
run valet use [email protected], this sets the php version to something different than what's in the .valetphprc file.
run valet use
run valet isolate

Diagnosis

sw_vers
ProductName:		macOS
ProductVersion:		13.1
BuildVersion:		22C65
valet --version
Laravel Valet 3.2.2
cat ~/.config/valet/config.json
{
    "tld": "test",
    "loopback": "127.0.0.1",
    "paths": [
        "/Users/mikey/.config/valet/Sites"
    ]
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/valet": "^3.2"
    }
}
composer global diagnose
Changed current directory to /Users/mikey/.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 git version 2.37.1
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: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version: OK
Composer version: 2.5.1
PHP version: 8.2.1
PHP binary path: /opt/homebrew/Cellar/php/8.2.1/bin/php
OpenSSL version: OpenSSL 1.1.1s  1 Nov 2022
cURL version: 7.87.0 libz 1.2.11 ssl (SecureTransport) OpenSSL/1.1.1s
zip: extension present, unzip present, 7-Zip not available
composer global outdated
Changed current directory to /Users/mikey/.composer
Legend:
! patch or minor release available - update recommended
~ major release available - update possible

Direct dependencies required in composer.json:
Everything up to date

Transitive dependencies not required in composer.json:
tightenco/collect v8.83.25 ~ v9.33.0 Collect - Illuminate Collections as a s...

ls -al /etc/sudoers.d/
total 16
drwxr-xr-x   4 root  wheel   128 14 Dec 22:58 .
drwxr-xr-x  80 root  wheel  2560 10 Jan 10:48 ..
-rw-r--r--   1 root  wheel    83  3 Feb  2022 brew
-rw-r--r--   1 root  wheel    86  3 Feb  2022 valet
brew config
HOMEBREW_VERSION: 3.6.18
ORIGIN: https://github.com/Homebrew/brew
HEAD: 106af035578d5f8716ae9510c1f9ad8c19f73a79
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 87ffaf4937410aa0af8de7c967583ed05e13a2d4
Core tap last commit: 44 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.0 build 1400
Git: 2.37.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.85.0 => /usr/bin/curl
macOS: 13.1-arm64
CLT: 14.2.0.0.1.1668646533
Xcode: N/A
Rosetta 2: false
brew services list
Name    Status User File
asimov  none            root 
dnsmasq none            root 
nginx   none            root 
php     none            root 
[email protected] none                 
[email protected] none            root 
redis   none
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.87 2.88 2.86
nginx 1.23.1 1.23.2 1.21.6 1.23.3
[email protected] 1.1.1s
php 8.1.13 8.2.1 8.1.9 8.1.8 8.1.6 8.1.11 8.1.2
[email protected] 7.4.33 7.4.32 7.4.27 7.4.30
[email protected] 8.0.24 8.0.15 8.0.22 8.0.25 8.0.27
brew outdated

brew tap
homebrew/cask
homebrew/core
homebrew/services
nicoverbruggen/cask
superfly/tap
php -v
PHP 8.2.1 (cli) (built: Jan  5 2023 19:28:02) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies
which -a php
/opt/homebrew/bin/php
php --ini
Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.2
Loaded Configuration File:         /opt/homebrew/etc/php/8.2/php.ini
Scan for additional .ini files in: /opt/homebrew/etc/php/8.2/conf.d
Additional .ini files parsed:      /opt/homebrew/etc/php/8.2/conf.d/error_log.ini,
/opt/homebrew/etc/php/8.2/conf.d/ext-opcache.ini,
/opt/homebrew/etc/php/8.2/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.23.3
curl --version
curl 7.85.0 (x86_64-apple-darwin22.0) libcurl/7.85.0 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.47.0
Release-Date: 2022-08-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe UnixSockets
php --ri curl
curl

cURL support => enabled
cURL Information => 7.87.0
Age => 10
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
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 => Yes
BROTLI => Yes
ALTSVC => Yes
HTTP3 => No
UNICODE => No
ZSTD => Yes
HSTS => Yes
GSASL => No
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtmpe, rtmps, rtmpt, rtmpte, rtmpts, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => aarch64-apple-darwin22.1.0
SSL Version => (SecureTransport) OpenSSL/1.1.1s
ZLib Version => 1.2.11
libSSH Version => libssh2/1.10.0

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

~/.composer/vendor/laravel/valet/bin/ngrok version
ngrok version 2.3.40
ls -al ~/.ngrok2
ls: /Users/mikey/.ngrok2: No such file or directory
brew info nginx
==> nginx: stable 1.23.3 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/opt/homebrew/Cellar/nginx/1.21.6 (23 files, 2.2MB)
  Built from source
/opt/homebrew/Cellar/nginx/1.23.1 (23 files, 2.2MB)
  Built from source
/opt/homebrew/Cellar/nginx/1.23.2 (23 files, 2.2MB)
  Built from source
/opt/homebrew/Cellar/nginx/1.23.3 (26 files, 2.2MB) *
  Poured from bottle on 2023-01-10 at 09:18:25
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: [email protected], pcre2
==> Options
--HEAD
	Install HEAD version
==> Caveats
Docroot is: /opt/homebrew/var/www

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

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To restart nginx after an upgrade:
brew services restart nginx
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 40,155 (30 days), 124,142 (90 days), 463,851 (365 days)
install-on-request: 40,096 (30 days), 123,975 (90 days), 463,066 (365 days)
build-error: 20 (30 days)

brew info php
==> php: stable 8.2.1 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/opt/homebrew/Cellar/php/8.1.2 (510 files, 81.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.6 (193 files, 33.7MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.8 (510 files, 81.7MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.9 (510 files, 81.7MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.11 (510 files, 81.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.13 (193 files, 33.7MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.1 (519 files, 83.3MB) *
  Poured from bottle on 2023-01-10 at 09:18:12
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, freetds, gd, gettext, gmp, icu4c, krb5, libpq, libsodium, libzip, oniguruma, openldap, [email protected], 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 php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.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:
/opt/homebrew/etc/php/8.2/

To restart php after an upgrade:
brew services restart php
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
==> Analytics
install: 120,668 (30 days), 381,405 (90 days), 1,469,985 (365 days)
install-on-request: 106,047 (30 days), 336,080 (90 days), 1,260,788 (365 days)
build-error: 264 (30 days)

brew info openssl
==> openssl@3: stable 3.0.7 (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/[email protected]
License: Apache-2.0
==> Dependencies
Required: ca-certificates
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@3/certs

and run
/opt/homebrew/opt/openssl@3/bin/c_rehash

openssl@3 is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

==> Analytics
install: 155,681 (30 days), 606,605 (90 days), 1,904,722 (365 days)
install-on-request: 72,252 (30 days), 313,452 (90 days), 1,309,167 (365 days)
build-error: 196 (30 days)

openssl version -a
LibreSSL 3.3.6
built on: date not available
platform: information not available
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"
openssl ciphers
AEAD-CHACHA20-POLY1305-SHA256:AEAD-AES256-GCM-SHA384:AEAD-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305: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: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 /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful
which -a php-fpm
/opt/homebrew/sbin/php-fpm
/opt/homebrew/opt/php/sbin/php-fpm -v
PHP 8.2.1 (fpm-fcgi) (built: Jan  5 2023 19:28:05)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies
sudo /opt/homebrew/opt/php/sbin/php-fpm -y /opt/homebrew/etc/php/8.2/php-fpm.conf --test
[10-Jan-2023 10:55:42] NOTICE: configuration file /opt/homebrew/etc/php/8.2/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   627 12 Dec 13:10 homebrew.mxcl.asimov.plist
-rw-r--r--   1 root  admin   797 10 Jan 09:38 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   685 10 Jan 10:41 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   781 10 Jan 09:37 homebrew.mxcl.php.plist
-rw-r--r--   1 root  admin   789 10 Jan 10:41 [email protected]
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22  2 Dec 11:37 /etc/resolv.conf -> ../var/run/resolv.conf
cat /etc/resolv.conf
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
nameserver 192.168.1.1
nameserver 192.168.1.1
ifconfig lo0
lo0: flags=8049 mtu 16384
	options=1203
	inet 127.0.0.1 netmask 0xff000000 
	inet6 ::1 prefixlen 128 
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
	nd6 options=201
sh -c 'echo "------\n/opt/homebrew/etc/nginx/valet/valet.conf\n---\n"; cat /opt/homebrew/etc/nginx/valet/valet.conf | grep -n "# valet loopback"; echo "\n------\n"'
------
/opt/homebrew/etc/nginx/valet/valet.conf
---

3: #listen VALET_LOOPBACK:80; # valet loopback

------

sh -c 'for file in ~/.config/valet/dnsmasq.d/*; do echo "------\n~/.config/valet/dnsmasq.d/$(basename $file)\n---\n"; cat $file; echo "\n------\n"; done'
------
~/.config/valet/dnsmasq.d/tld-test.conf
---

address=/.test/127.0.0.1
listen-address=127.0.0.1

------

sh -c 'for file in ~/.config/valet/nginx/*; do echo "------\n~/.config/valet/nginx/$(basename $file)\n---\n"; cat $file | grep -n "# valet loopback"; echo "\n------\n"; done'
------
~/.config/valet/nginx/atomicsmash.test
---

3: #listen 127.0.0.1:80; # valet loopback
10: #listen 127.0.0.1:443 ssl http2; # valet loopback
54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/blocks-test.test

3: #listen 127.0.0.1:80; # valet loopback
10: #listen 127.0.0.1:443 ssl http2; # valet loopback
54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/oxygenfreejumping.test

4: #listen 127.0.0.1:80; # valet loopback
11: #listen 127.0.0.1:443 ssl http2; # valet loopback
55: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/piktfresh.test

3: #listen 127.0.0.1:80; # valet loopback
10: #listen 127.0.0.1:443 ssl http2; # valet loopback
54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/plugin-dev.test

3: #listen 127.0.0.1:80; # valet loopback
10: #listen 127.0.0.1:443 ssl http2; # valet loopback
54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/public.test

3: #listen 127.0.0.1:80; # valet loopback
10: #listen 127.0.0.1:443 ssl http2; # valet loopback
54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/snap.test

3: #listen 127.0.0.1:80; # valet loopback
10: #listen 127.0.0.1:443 ssl http2; # valet loopback
54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/thegrandappeal.test

3: #listen 127.0.0.1:80; # valet loopback
10: #listen 127.0.0.1:443 ssl http2; # valet loopback
54: #listen 127.0.0.1:60; # valet loopback

------

@driesvints
Copy link
Member

run valet use [email protected], this sets the php version to something different than what's in the .valetphprc file.

Why are you doing this?

@mikeybinns
Copy link
Author

I guess you don't really need to, I just wanted to make sure that the global php version and the expected new version didn't match to make it easier to see if it works.
If the global version on your machine is 8.0, and you tried to set the php version to 8.0 using the .valetphprc, you could still get the message "Valet is using [email protected]." but it would be unclear if the version came from the already set global version or if it came from the .valetphprc file because the command doesn't fail if it doesn't find the file.

@mikeybinns
Copy link
Author

An alternate solution would just be to make sure the php version specified in the .valetphprc is different from your current global php version

@MeMattStone
Copy link
Contributor

I'm the work colleague mentioned above, and I am also the original contributor of the .valetphprc feature.

I've done some investigating and on my personal MacBook where running valet use successfully reads the project's .valetphprc file and switches the version I'm using ~/Sites as a parked directory, but on my work MacBook where the command ignores the file I'm using linked sites to individual directories.

The following line of code seems to be the culprit:

if ($site = $this->parked()->merge($this->links())->where('site', $site)->first()) {
as it returns false for linked sites

@driesvints
Copy link
Member

@MeMattStone can you send in a PR?

@MeMattStone
Copy link
Contributor

Yes of course, I'll do a bit more testing to verify a solution and submit a PR

@ps-sean
Copy link

ps-sean commented Jan 12, 2023

@MeMattStone unsure if related, but I have the same setup and after isolating a site I lose access to the 'valet php' and 'valet composer' commands. Running either of these returns "Sorry,: command not found". These commands run as expected on unisolated sites

@driesvints
Copy link
Member

This will be fixed in the upcoming v4 release: #1347

@mattstauffer
Copy link
Collaborator

Sorry to be a pain @driesvints but #1347 didn't actually solve that issue, it just added a second file that can be used for these sorts of configs. Still curious to get @MeMattStone's input!

@mattstauffer mattstauffer reopened this Jan 19, 2023
@MeMattStone
Copy link
Contributor

Sorry for delay in getting a PR up for this, I think I've figured out the issue but need to do a bit more testing so will share my findings are submit a PR soon

@mattstauffer
Copy link
Collaborator

@MeMattStone no worries! :)

@mattstauffer
Copy link
Collaborator

I tried to reproduce this using my local branch of Valet v4, in which I don't think I modified this behavior:

php -v # Outputs PHP 8.1.14
cd /tmp
mkdir linkme
cd linkme
mkdir public
echo "<?php echo phpversion();" > public/index.php
echo "[email protected]" > .valetphprc
valet link
valet use # Found 'linkme/.valetrc' or 'linkme/.valetphprc' specifying version: [email protected]
valet php -v # [email protected]
php -v # [email protected]
valet use [email protected]
valet isolate # Found 'linkme/.valetrc' or 'linkme/.valetphprc' specifying version: [email protected]
valet php -v # [email protected]
php -v # [email protected]

I'll try the same thing on a Valet 3 branch shortly.

@mattstauffer
Copy link
Collaborator

OK, Valet v3, on the same directory from my previous comment:

valet -v # Laravel Valet 3.3.0
php -v # [email protected]
valet isolate # outputs two lines??? this is strange! 
# Found 'linkme/.valetphprc' specifying version:
# Found 'linkme/.valetphprc' specifying version: [email protected]
php -v # [email protected]
valet php -v # [email protected]
valet unisolate
valet use # Found 'linkme/.valetphprc' specifying version: [email protected]
php -v # [email protected]
valet php -v # [email protected]

So other than the weird double-output when isolating, it seems to work fine for me. Am I doing it wrong?

@mattstauffer
Copy link
Collaborator

The following line of code seems to be the culprit:

if ($site = $this->parked()->merge($this->links())->where('site', $site)->first()) {

as it returns false for linked sites

I'll try this issue again with no parked directories maybe?

@mattstauffer
Copy link
Collaborator

Nope. With no parked directories, and only linked directories, I still can't get it to fail.

@driesvints
Copy link
Member

@mattstauffer I guess we can close this now?

@mikeybinns
Copy link
Author

Hi, I'm currently re-verifying with @MeMattStone, I think there may be an element of human error here, give me a little bit to confirm and I'll close the branch if it's not a problem :)

@mikeybinns
Copy link
Author

Hey, I was incorrect in my last comment, I can definitely still recreate this issue on my machine. What's interesting is that I can get it to work if I add some parked domains, so it appears to be something on line 1162 where $this->parked() returns an empty collection which somehow breaks the rest of the if statement (it doesn't appear to try and find that valetphprc file because the if statement fails.)

@mattstauffer
Copy link
Collaborator

@mikeybinns Can you uninstall Valet, restart your computer, reinstall Valet, and keep track of the steps between a fresh install and being able to reproduce this issue?

Thanks!

@mikeybinns
Copy link
Author

Okay, I've discovered what the issue is.

When we link our sites at work, we use the command valet link --secure SITENAME because we have a folder setup where the site we're trying to locally host is in a subfolder of the root called public. Then our root folder has all our config files, package.json etc.

Where this falls over is if we make the site name different than the root folder name. Because valet use always get's the $site parameter from the folder name, and you can't specify a site name, this always ended up failing because it couldn't locate the site it was trying to find. If we try and run this command in the public folder where we run our link command, it always tries to find a site named public and fails.

What doesn't make sense is how it's trying to find the .valetphprc file, because for valet use it will always be in the folder you're in, there's no need to get the site to find the site path to find the file, and because you're setting the global PHP version anyway, it shouldn't matter what site you're trying to view, if you run valet use, it should just search in the folder you're in for the .valetphprc.

This also explains why this broke for me after updating from v2 to v3, as v3 was when the phpRcVersion was added, and while I can't find the valet use code in v2, I assume it doesn't have this if statement to find the registered site, it just looks in the current working directory for the .valetphprc file.

Because of the above discovery, I think there's 2 changes that need to happen.

  1. valet use should search in the current directory for a .valetphprc file, or add a --site parameter to specify a site like other commands have. I would go for option a as valet use shouldn't relate to a specific site anyway.
  2. @MeMattStone and I will need to update our work dev environment so we can link valet from the root folder, not the sub folder, we can likely do this by adding an index.php file to the root which points to the public folder.

Updated steps to reproduce:
Update to v3.3.1
Navigate in terminal to project root
create .valetphprc and use the contents [email protected]
Make sure the project root is not parked, then link it using the --site parameter to a sitename that is different from the project root folder name.
run valet use [email protected], this sets the php version to something different than what's in the .valetphprc file.
run valet use
run valet isolate

@mattstauffer
Copy link
Collaborator

@mikeybinns @MeMattStone Can y'all test out this PR for me?

#1361

@mikeybinns
Copy link
Author

@mattstauffer I just downloaded your PR branch and then tested Valet use, it works for me.
@MeMattStone have you tried it or are you just happy to close it?

@MeMattStone
Copy link
Contributor

MeMattStone commented Feb 10, 2023

@mikeybinns Working for me too

@mattstauffer
Copy link
Collaborator

Fantastic. I'm going to merge it then!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants