Valet: In Brew.php line 187: Unable to determine linked PHP.

Created on 8 Mar 2018  Β·  62Comments  Β·  Source: laravel/valet

I try methods: composer global update, install php 72, brew upgrade, but error repeat and repeat ? what can i do, to run service ? valet version 2.0.8

Most helpful comment

I've had the same problem tonight, and here's what I did to get it running:

brew unlink php && brew link php
brew services restart --all
composer global update
valet start

It would be nice if Valet had some suggestions on what to do when "Unable to determine linked PHP." comes up.

All 62 comments

I've had the same problem tonight, and here's what I did to get it running:

brew unlink php && brew link php
brew services restart --all
composer global update
valet start

It would be nice if Valet had some suggestions on what to do when "Unable to determine linked PHP." comes up.

@donaldallen wrote:

It would be nice if Valet had some suggestions on what to do when "Unable to determine linked PHP." comes up.

Two code references:
https://github.com/laravel/valet/blob/master/cli/Valet/Brew.php#L178-L179
In this one it's looking to ensure that the php binary is linked. So, if you've unlinked all the installed PHP versions, then you'll get that error message.

Next it moves on to verify that the linked php binary is a supported one, per this list:
https://github.com/laravel/valet/blob/master/cli/Valet/Brew.php#L53-L56

Getting some error here, tried to follow my symlink and it looks like this ../Cellar/php/7.2.2_14/bin/php.

Looking at how it matches, it looks for a full path containing one of the supported versions.

The supported php version looks for strings named like this php72, which of course is not in the path.

@uruloke Should this not be caught by the first item php?

uruloke, Yes, I commented locally this checking, and valet was started, but it is not good decision

@scherii You are right, it should be caught by that, didn't see it. Gotta test this out a little locally and see if I can find an great solution.

After cloning the repo I can't reproduce the error, lol.
If OP or someone else could tell how to reproduce the error, I will gladly try to fix it.

Try brew update php to another version and change link

@orangeShadow Just uninstalled php72 then installed php71, linked to php71, upgraded to php72 and linked to php72, then ran valet start and everything seems to work.

@uruloke, Can you write your file path and name for php link

Brew has promoted php7.2 to core, so it is called php now.
https://github.com/laravel/valet/blob/master/cli/Valet/Brew.php#L185 will always throw exception until the logic is revised.

To get mine working, I edited
/Users/<your_username>/.composer/vendor/laravel/valet/cli/Valet/Brew.php
from

return strpos($resolvedPath, "/$version/") !== false;

to

if ($version === 0 || strpos($resolvedPath, "/$version/") !== false) return true;

@scherii,

Should this not be caught by the first item php?

You’d think that. But for some reason it didn’t for me on the path ../Cellar/php/7.2.3_2/bin/php… But when I added an item '7.2.3_2' to the array on that line all worked fine. No clue what’s tripping it up there.

brew unlink php && brew link php
brew services restart --all
composer global update
valet start

That fixes it for me, somehow.

ln -s /usr/local/Cellar/php71/7.1.16_1/bin /usr/local/bin/php

➜ ~ valet install
Stopping nginx...
Installing nginx configuration...
Installing nginx directory...
Updating PHP configuration...
Restarting [email protected]...
Restarting dnsmasq...
Restarting nginx...

wild guess that most people here having the issue only care if it's 7.1+ and thus are fighting an unnecessary fight. if possible just trash all php things from the system with uninstall, doctor, cleanup and just install newest php (currently 7.2) and formula name will be php not php@version, it has been fixed in brew core formula names for some time and install php@version is used only if you explicitly want older php.

valet install

In Brew.php line 182:
Unable to determine linked PHP.

brew unlink php && brew link php

Error: No such keg: /usr/local/Cellar/php

brew install php worked in my case to resolve the issue

valet install

Valet installed successfully!

Also here is a nice comprehensive guide to upgrading brew and php. Nicely put together:

https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions

this worked for me...

brew unlink php

brew link --overwrite php

valet install

If you follow donaldallen's comment and it still doesn't fix it you can check if it's symlinked correctly.

$ which php
/usr/local/opt/[email protected]/bin/php

Then create a symlink to where this is looking for it: https://github.com/laravel/valet/blob/master/cli/Valet/Brew.php#L181

ln -s /usr/local/opt/[email protected]/bin/php /usr/local/bin/php

That was the fix on mine.

Hi, I found problem !!!!

return $this->supportedPhpVersions()->first(function ($version) use ($resolvedPath) {
            $resolvedPathNormalized= preg_replace('/([@|\.])/', '', $resolvedPath);
            $versionNormalized = preg_replace('/([@|\.])/', '', $version);
            return strpos($resolvedPathNormalized, "/$versionNormalized/") !== false;
        }, function () {
            throw new DomainException("Unable to determine linked PHP.");
        });

In line 187 $version is a key of constant's array, but if you set second parameter it would be a $version

return $this->supportedPhpVersions()->first(function ($key, $version) use ($resolvedPath) {
            $resolvedPathNormalized= preg_replace('/([@|\.])/', '', $resolvedPath);
            $versionNormalized = preg_replace('/([@|\.])/', '', $version);
            return strpos($resolvedPathNormalized, "/$versionNormalized/") !== false;
        }, function () {
            throw new DomainException("Unable to determine linked PHP.");
        });

The code seems to check only if php is a symlink, however I just installed MacOs High Sierra in the latest version and it comes with PHP 7.1.14 which should be fine in many cases, might even be wanted by some systems that don't fully work with PHP 7.2...

So I think the logic should take into consideration that the systems built in PHP version might be okay as well!

Brew.php:

    if (!$this->files->isLink('/usr/local/bin/php')) {
        throw new DomainException("Unable to determine linked PHP.");
    }

I think this can be closed, as multiple improvements have been made to address the homebrew changes that precipitated this.

fixed by:

$ ln -s /usr/local/opt/[email protected]/bin/php /usr/local/bin/php

My way to fix this was ti rewrite current php version: brew link [email protected] --force --overwrite
That worked for me in similar case. If you have questions in the whole process - ping me as well. Probably, I can help ;)

valet install

In Brew.php line 182:
Unable to determine linked PHP.

brew unlink php && brew link php

Error: No such keg: /usr/local/Cellar/php

brew install php worked in my case to resolve the issue

valet install

Valet installed successfully!

this works for me too.

(I try to follow the docs on laravel.com to run brew install [email protected], but it failed)

@hezll If "Unable to determine linked PHP" is on your line 182, you're not running the latest version of Valet. Please update and try again if you have any issues. Thanks!

This helped me

in file: /Users//.composer/vendor/weprovide/valet-plus/cli/Valet/Brew.php

on line: 16
const PHP_V72_BREWNAME = 'php';

change to :

const PHP_V72_BREWNAME = '[email protected]';

@andrey-bondarenko that path shows you're using Valet-Plus, which is a poorly-named alternative which has no connection to this project at all :)

I'm on MacOS 10.14 and had to brew link --force [email protected]

valet install

In Brew.php line 182:
Unable to determine linked PHP.

brew unlink php && brew link php

Error: No such keg: /usr/local/Cellar/php

brew install php worked in my case to resolve the issue

valet install

Valet installed successfully!

Work for me also.

Ended up having to do:

brew unlink php && brew link php --overwrite --force

Just overwrite and just force wasn't enough :)

Now it's problem with line 195 with latest Valet T_T
Tried install [email protected] or php (aka [email protected]) still not work

tucq88 are you still having the issue at line 195? I am as well, anyone have any ideas?

@thomasbyoung Yeah still mate, I'm going back to Vagrant which is much more painful :(

@thomasbyoung @tucq88

If it's saying "Unable to determine linked PHP", it means valet isn't finding PHP in the location it expects it. This is almost always a Homebrew issue, typically caused by swapping back and forth between mixed PHP versions. It can be a little confusing to troubleshoot what Homebrew has done, but usually unlinking and relinking php will suffice (as well as using a supported php version of course).

To better understand what your unique fix may require, please provide the output of each of the following commands:
which php
php -v
brew services list
brew info php

Also, what's the "history" of this computer? What PHP versions have you been using? When did your valet problem/s start? How does that match up with PHP upgrades or valet upgrades or other Homebrew changes you've made?

Working on a brand new machine. Valet is working perfectly on the old one. Getting the error listed above (by other people, line 195) on a fresh install.

  1. Updated to macOS Mojave 10.14.2 via App Store
  2. Started following the steps at https://laravel.com/docs/5.7/valet#installation - with one exception, I installed [email protected] instead of [email protected] (as I wanted to stick with the version I know my current projects are tested on, for now).
  3. The valet install command fails with the error mentioned:
In Brew.php line 195:

  Unable to determine linked PHP.

The history of this computer is nothing. It's new. Installed PHP 7.1, Valet problem starts immediately on first install. I'd prefer to avoid having to install PHP 7.2 for now, if possible to get it working without it.

which php

/usr/bin/php

php -v

PHP 7.1.19 (cli) (built: Aug 17 2018 20:10:18) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

brew services list

Name    Status  User   Plist
nginx   stopped        
[email protected] started shanes /Users/shanes/Library/LaunchAgents/[email protected]

brew info php

php: stable 7.3.0 (bottled)
General-purpose scripting language
https://secure.php.net/
Not installed
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 βœ”, libpng βœ”, libpq βœ”, libsodium ✘, libzip βœ”, openldap βœ”, openssl βœ”, pcre βœ”, 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.3/

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: 43,800 (30 days), 122,653 (90 days), 383,832 (365 days)
install_on_request: 39,843 (30 days), 111,615 (90 days), 346,530 (365 days)
build_error: 0 (30 days)

One strange thing above are the references to PHP 7.3

Running brew services start php fails with:

Error: Formula `php` is not installed.

However, these work fine (and the first one is what I ran after the install, as per Homebrew's recommendation):

Hmm, interesting.

brew unlink [email protected] && brew link [email protected] --force

Unlinking /usr/local/Cellar/[email protected]/7.1.25... 0 symlinks removed
Linking /usr/local/Cellar/[email protected]/7.1.25... 25 symlinks created

The symlinks were initially missing.

Afterwards, valet install works. πŸ’―


@tucq88 and @thomasbyoung - try one of the following, depending on what version of PHP you have installed on your system:

Then re-try the valet install command.

No luck for me :(

Now it's on line 205 =))

@tucq88 please answer the questions I posted above.

Hmm, interesting.

brew unlink [email protected] && brew link [email protected] --force

Unlinking /usr/local/Cellar/[email protected]/7.1.25... 0 symlinks removed
Linking /usr/local/Cellar/[email protected]/7.1.25... 25 symlinks created

The symlinks were initially missing.

Afterwards, valet install works. πŸ’―

How is it interesting? It's an obvious bug that these people won't fix for some reason... See: https://github.com/laravel/valet/issues/533#issuecomment-394101964

@OZZlE These people? Please direct me to the pull request where you fixed it and I'll be more than happy to review it.

For anyone who is curious, we're taking a look and trying to figure out a good solution. "Just allow non-Homebrew PHP" may not be a good enough solution; "just allow non-symlinks" may not be a good enough solution; "I have to run a Homebrew command to get my Valet working and therefore it's Valet's fault" is a bad take.

If anyone has all of this in their brain and can fully conceptualize the best fix, please, create a new issue and/or pull request and guide us here. Otherwise, please respect the amount of work @drbyte has put into helping people here--with no benefit or payment to himself.

Perhaps a quick fix (meanwhile) is to document any workarounds as part of the install instructions. I suspect anyone installing this on a fresh machine with latest macOS will run into the problem.

This looks to be the place: https://github.com/laravel/docs/blob/5.7/valet.md#installation

I may be able to submit something myself, but likely not this week.

For anyone who is curious, we're taking a look and trying to figure out a good solution. "Just allow non-Homebrew PHP" may not be a good enough solution; "just allow non-symlinks" may not be a good enough solution; "I have to run a Homebrew command to get my Valet working and therefore it's Valet's fault" is a bad take.

If anyone has all of this in their brain and can fully conceptualize the best fix, please, create a new issue and/or pull request and guide us here. Otherwise, please respect the amount of work @drbyte has put into helping people here--with no benefit or payment to himself.

Sorry I was a bit cranky :) What about doing like this: if php is exists and is not a symlink; output this php with version and ask the user if they would like to keep it or update to the latest php, if they go with latest then force symlink it to that.

I think we have a fix (written by @drbyte, no surprise) on master. Anyone who wants to take a look can; I'm letting it sit there for a few days before I release, but I'll likely release within the next day or two.

Is this out already?

So to solve the problem, simply create the directory with sudo mkdir /usr/local/sbin and then set the correct ownership on it with sudo chown -R `whoami`:admin /usr/local/sbin.

then:

$ brew unlink php && brew link php
$ brew services restart --all
$ composer global update
$ valet start

I found two ways to resolve this on my machines.

First is to not use a specific version of php:
$ brew install php (you'll get the latest one)
$ brew link php
$ valet restart

Second solution is for when you want to use a specific version of PHP:
$ brew install [email protected]
$ brew link [email protected]
$ valet use [email protected] (which will restart, too)

Type of @delino12 solve my problem! Thanks dude!

Returning to this thread I already replied to after spending an hour trying to get it to work :)

brew install php doesn't install 7.3 but grabs 7.2 (after a brew update and upgrade)
brew link [email protected] gives Warning: [email protected] is keg-only and must be linked with --force

and no matter what valet start or valet restart gives the unable to determine linked php error. Stumped.

@brianhogg Ya, the brew update should have made sure you have the latest version endpoints to install for.
My first reaction is that that maybe suggests something amuck with your homebrew install.
I'd start by running brew doctor and exploring its suggestions.

A more aggressive advanced step you could explore is to delete your /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core directory, and then run brew doctor again to have it re-install the core taps that are used for installing php with brew.

Also, what does valet --version say? Today the latest is 2.3.3.

@delino12 helped me a lot! However, first you need to understand that you still have two php version on your mac.

When you use an empty .php file and write down phpinfo(); you might see that the version is not correctly installed, even though if you type down php -v in your terminal you see the newest version.

What I found out is that you need to create a new symlink for your mac.

  1. Find out where your newest php is. Use for example which php or brew list php
  2. Now you need to remove the local php that is installed with rm -f /usr/local/bin/php. This removes the php bin file.
  3. Now we are creating a symlink to the newest php bin file just by: ln -s /usr/local/Cellar/php/7.3.10/bin /usr/local/bin/php (Warning! Please update the first path to the path you saw with which php)

Now it works for me :) I hope it helped you as well

Rather than manually linking, Homebrew can do the symlinking for you:

brew unlink [email protected]
brew link [email protected]

Sometimes adding --force can be useful.

Anybody using macOS 10.15 the file to amend now is ~/.zshrc.

Example being.

# export PATH="/usr/local/opt/[email protected]/bin:$PATH"
# export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
# export PATH="/usr/local/opt/[email protected]/bin:$PATH"
# export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"

And now this works fine for me. Best to also open a new terminal to see it working.

brew unlink [email protected] && brew link --force [email protected]  

After updating to PHP 7.4 :

In Brew.php line 251:
Unable to determine linked PHP when parsing '7.4' 

I had the same issue, and this was what I did to fix it:

Check your current php version
brew unlink php
valet use php@current version ( eg:- valet use [email protected] )
brew services restart --all
composer global update
valet start

Hopefully, this helpsπŸ™‚

Im use Valet+ this code bellow help me:
brew unlink [email protected] && brew link --force [email protected]

Discussion about Valet-Plus should be done in their repository.
(Otherwise the advice given might be irrelevant/incomplete/incorrect. Such as in this case, where valet-php doesn't exist in official Laravel Valet.)

Im use Valet+ this code bellow help me:
brew unlink [email protected] && brew link --force [email protected]

Discussion about Valet-Plus should be done in their repository.

sorry!

Valet doesn't support PHP version: [email protected] (try something like 'php7.2' ins tead)
but some vender need [email protected]
how i to do?

@AlvinQinwen please open a new issue if you have questions. Also, please update your copy of Valet and re-test before you do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dustinleblanc picture dustinleblanc  Β·  4Comments

idmahbub picture idmahbub  Β·  3Comments

webartistse picture webartistse  Β·  4Comments

LucidNinja picture LucidNinja  Β·  4Comments

Flimm picture Flimm  Β·  5Comments