Valet: Error after upgrading PHP: "Uncaught Error: Call to undefined function Valet\collect()"

Created on 9 Apr 2020  Â·  16Comments  Â·  Source: laravel/valet

I just upgraded my PHP from 7.3 to 7.4, and valet install gives me this error:

PHP Fatal error:  Uncaught Error: Call to undefined function Valet\collect() in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php:202
Stack trace:
#0 /Users/sully/.composer/vendor/laravel/valet/cli/includes/helpers.php(149): Valet\Configuration->Valet\{closure}(Array)
#1 /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php(205): Valet\tap(Array, Object(Closure))
#2 /Users/sully/.composer/vendor/laravel/valet/cli/includes/facades.php(28): Valet\Configuration->prune()
#3 /Users/sully/.composer/vendor/laravel/valet/cli/valet.php(43): Facade::__callStatic('prune', Array)
#4 {main}
  thrown in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php on line 202

Fatal error: Uncaught Error: Call to undefined function Valet\collect() in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php:202
Stack trace:
#0 /Users/sully/.composer/vendor/laravel/valet/cli/includes/helpers.php(149): Valet\Configuration->Valet\{closure}(Array)
#1 /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php(205): Valet\tap(Array, Object(Closure))
#2 /Users/sully/.composer/vendor/laravel/valet/cli/includes/facades.php(28): Valet\Configuration->prune()
#3 /Users/sully/.composer/vendor/laravel/valet/cli/valet.php(43): Facade::__callStatic('prune', Array)
#4 {main}
  thrown in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php on line 202

I tried removing my global packages and reinstalling them and the issue persists:

rm -rf ~/.composer/vendor ~/.composer/composer.lock && composer global update

Most helpful comment

@saleh-mir
Three things come up in the responses you posted:

  1. Composer version
    > composer global diagnose
    > Composer version: 1.8.4
    > Checking composer version: You are not running the latest stable version, run composer self-update to update (1.8.4 => 1.10.5)

I suggest upgrading composer as they recommend, via: composer self-update

Particularly, I wonder if the older composer version doesn't work well with PHP 7.4.

  1. dyld library errors
    > dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib

This happens after [email protected] gets upgraded.(I saw it after the 1.1.1f and 1.1.1t updates)

The quickest patch I've found is to run this:

ln -s /usr/local/Cellar/openssl/1.0.2t/lib/libcrypto.1.0.0.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
ln -s /usr/local/Cellar/openssl/1.0.2t/lib/libssl.1.0.0.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  1. Other homebrew software versions out of date
    > curl-openssl 7.69.1 7.64.1
    dnsmasq 2.80
    nginx 1.17.10

There are newer versions of these available. Running brew upgrade is recommended.

  1. Other dependencies

I also see that your laravel/envoy version in your global composer.json refers to an older version. This may be telling composer to use older constraints than necessary.

  1. Next steps
    After doing all the above, I was going to suggest composer global update but given the out-of-date envoy version, and the fact that envoy and valet are the only things in your global composer.json, I suggest the following in your case:
composer clear-cache
rm -rf ~/.composer/composer.json ~/.composer/composer.lock ~/.composer/vendor
composer global require laravel/valet
valet install

and then after Valet is working properly composer global require laravel/envoy to put envoy back again.

All 16 comments

I have the same problem

thx

I have the same problem, how to solve? thx!

Can you all take a look at this issue? It's almost definitely a Composer version conflict issue, which is sadly pretty common with global Composer:

https://github.com/laravel/valet/issues/706

If that doesnt' help, please let me know and we'll dig in.

@saleh-mir @LonnyX @oiuv @QingHuanMoon
Does upgrading Valet to v2.9.1 (released today) solve this for you?

i have solved this problem :

rm -rf ~/.composer/vendor ~/.composer/composer.lock && composer global update
composer global remove laravel/valet
composer global require laravel/valet

@drbyte sadly no.

@oiuv this is basically what I said I did in the original post. I did try again now, same problem.

I downgraded to 2.9.0 and it works.

rm -rf ~/.composer/vendor ~/.composer/composer.lock
edit ~/.composer/composer.json and change to this "laravel/valet": "^2.9"
composer global install

Do not execute composer global update

@LonnyX The only change introduced in 2.9.1 was to allow a higher version of Collect, so it seems unlikely that it was the downgrade that fixed it.

Also, if you change something in composer.json, delete composer.lock, then composer install, it's the same as running composer update.

@saleh-mir So you've upgraded your global Valet version to 2.9.1, temporarily removed the Laravel installer, deleted your global vendor folder and composer.lock file (just for safety--composer update really should do the same but what the check), and run composer global install and it's still showing this problem?

@mattstauffer Yes!. I'm running out of possible solutions here. Except for fresh installing macOS 😂

For the sake of establishing a baseline, what's the output of the following?

sw_vers
valet --version
cat ~/.config/valet/config.json
cat ~/.composer/composer.json
ls -al /etc/sudoers.d/
brew config
brew services list
brew list --versions | grep -E '(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s'
php -v
which -a php
php --ini
nginx -v
which -a php-fpm
sudo /usr/local/opt/php/sbin/php-fpm --test
sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/7.4/php-fpm.conf --test
composer global diagnose

@drbyte:

sw_vers

ProductName:    Mac OS X
ProductVersion: 10.15.4
BuildVersion:   19E266

valet --version

PHP Fatal error:  Uncaught Error: Call to undefined function Valet\collect() in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php:202
Stack trace:
#0 /Users/sully/.composer/vendor/laravel/valet/cli/includes/helpers.php(149): Valet\Configuration->Valet\{closure}(Array)
#1 /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php(205): Valet\tap(Array, Object(Closure))
#2 /Users/sully/.composer/vendor/laravel/valet/cli/includes/facades.php(28): Valet\Configuration->prune()
#3 /Users/sully/.composer/vendor/laravel/valet/cli/valet.php(43): Facade::__callStatic('prune', Array)
#4 {main}
  thrown in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php on line 202

Fatal error: Uncaught Error: Call to undefined function Valet\collect() in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php:202
Stack trace:
#0 /Users/sully/.composer/vendor/laravel/valet/cli/includes/helpers.php(149): Valet\Configuration->Valet\{closure}(Array)
#1 /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php(205): Valet\tap(Array, Object(Closure))
#2 /Users/sully/.composer/vendor/laravel/valet/cli/includes/facades.php(28): Valet\Configuration->prune()
#3 /Users/sully/.composer/vendor/laravel/valet/cli/valet.php(43): Facade::__callStatic('prune', Array)
#4 {main}
  thrown in /Users/sully/.composer/vendor/laravel/valet/cli/Valet/Configuration.php on line 202

cat ~/.config/valet/config.json

{
    "tld": "test",
    "paths": [
        "/Users/sully/Codes/sites"
    ]
}

cat ~/.composer/composer.json

{
    "require": {
        "laravel/envoy": "^1.6",
        "laravel/valet": "^2.9"
    }
}

ls -al /etc/sudoers.d/

total 0
drwxr-xr-x   2 root  wheel    64 Aug 24  2019 .
drwxr-xr-x  86 root  wheel  2752 Apr 21 23:41 ..

brew config

HOMEBREW_VERSION: 2.2.13
ORIGIN: https://github.com/Homebrew/brew
HEAD: 3d9cf83fec45a75af61551f53d25383abe009d31
Last commit: 10 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 64b782f2cde0c1644384f17ec28719723b158303
Core tap last commit: 2 days ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_MAKE_JOBS: 4
CPU: quad-core 64-bit skylake
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Clang: 11.0 build 1100
Git: 2.21.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.4-x86_64
CLT: 11.0.33.17
Xcode: 11.4

brew services list

Name          Status  User  Plist
dnsmasq       started root  /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
nginx         started root  /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php           started root  /Library/LaunchDaemons/homebrew.mxcl.php.plist
postgresql    started sully /Users/sully/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql@11 stopped
redis         started sully /Users/sully/Library/LaunchAgents/homebrew.mxcl.redis.plist
stunnel       stopped
unbound       started root  /Library/LaunchDaemons/homebrew.mxcl.unbound.plist

brew list --versions | grep -E '(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d..*)?\s'

curl-openssl 7.69.1 7.64.1
dnsmasq 2.80
nginx 1.15.11
openssl 1.0.2s
[email protected] 1.1.1f 1.1.1d
php 7.4.4

php -v

PHP 7.4.4 (cli) (built: Mar 19 2020 20:12:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, 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

nginx -v

dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/bin/nginx
  Reason: image not found
[1]    43410 abort      nginx -v

which -a php-fpm

/usr/local/sbin/php-fpm
/usr/sbin/php-fpm

sudo /usr/local/opt/php/sbin/php-fpm --test

[23-Apr-2020 16:32:08] NOTICE: configuration file /usr/local/etc/php/7.4/php-fpm.conf test is successful

sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/7.4/php-fpm.conf --test

[23-Apr-2020 16:32:19] NOTICE: configuration file /usr/local/etc/php/7.4/php-fpm.conf test is successful

composer global diagnose

Changed current directory to /Users/sully/.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.8.4 => 1.10.5)
Composer version: 1.8.4
PHP version: 7.4.4
PHP binary path: /usr/local/Cellar/php/7.4.4/bin/php

@saleh-mir
Three things come up in the responses you posted:

  1. Composer version
    > composer global diagnose
    > Composer version: 1.8.4
    > Checking composer version: You are not running the latest stable version, run composer self-update to update (1.8.4 => 1.10.5)

I suggest upgrading composer as they recommend, via: composer self-update

Particularly, I wonder if the older composer version doesn't work well with PHP 7.4.

  1. dyld library errors
    > dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib

This happens after [email protected] gets upgraded.(I saw it after the 1.1.1f and 1.1.1t updates)

The quickest patch I've found is to run this:

ln -s /usr/local/Cellar/openssl/1.0.2t/lib/libcrypto.1.0.0.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
ln -s /usr/local/Cellar/openssl/1.0.2t/lib/libssl.1.0.0.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  1. Other homebrew software versions out of date
    > curl-openssl 7.69.1 7.64.1
    dnsmasq 2.80
    nginx 1.17.10

There are newer versions of these available. Running brew upgrade is recommended.

  1. Other dependencies

I also see that your laravel/envoy version in your global composer.json refers to an older version. This may be telling composer to use older constraints than necessary.

  1. Next steps
    After doing all the above, I was going to suggest composer global update but given the out-of-date envoy version, and the fact that envoy and valet are the only things in your global composer.json, I suggest the following in your case:
composer clear-cache
rm -rf ~/.composer/composer.json ~/.composer/composer.lock ~/.composer/vendor
composer global require laravel/valet
valet install

and then after Valet is working properly composer global require laravel/envoy to put envoy back again.

@drbyte I did everything you said except step 2 and 4. It's fixed! Thank you!

Shoot, apparently the one makes it problem for me was the laravel/envoy, had to do step 5 to get everything back up and running

Thanks for this!

You don't have to be brutal like this ;-)

Just run composer outdated
Output will look like this

illuminate/support v4.2.17 v8.19.0
laravel/envoy      v1.6.5  v2.4.0  Elegant SSH tasks for PHP

Then edit composer.json and update the version constraints.

After this run composer update and everything will be fine again :-D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webartistse picture webartistse  Â·  4Comments

tomirons picture tomirons  Â·  4Comments

EHLOVader picture EHLOVader  Â·  4Comments

eberkund picture eberkund  Â·  4Comments

TimOgilvy picture TimOgilvy  Â·  3Comments