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

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

Closed
orangeShadow opened this issue Mar 8, 2018 · 64 comments
Closed

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

orangeShadow opened this issue Mar 8, 2018 · 64 comments

Comments

@orangeShadow
Copy link

orangeShadow commented Mar 8, 2018

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

@donaldallen
Copy link

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.

@drbyte
Copy link
Contributor

drbyte commented Mar 11, 2018

@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

@olivernybroe
Copy link

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.

@scherii
Copy link

scherii commented Mar 13, 2018

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

@orangeShadow
Copy link
Author

orangeShadow commented Mar 13, 2018

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

@olivernybroe
Copy link

@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.

@olivernybroe
Copy link

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.

@orangeShadow
Copy link
Author

orangeShadow commented Mar 13, 2018

Try brew update php to another version and change link

@olivernybroe
Copy 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.

@orangeShadow
Copy link
Author

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

@lesaff
Copy link

lesaff commented Mar 16, 2018

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;

@Zegnat
Copy link

Zegnat commented Mar 18, 2018

@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.

@MelMacaluso
Copy link

MelMacaluso commented Apr 13, 2018

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

That fixes it for me, somehow.

@delino12
Copy link

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 php@7.1...
Restarting dnsmasq...
Restarting nginx...

@kroko
Copy link
Contributor

kroko commented Apr 25, 2018

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.

@khadkaPratik
Copy link

khadkaPratik commented Apr 26, 2018

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!

@aurawindsurfing
Copy link

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

@mikoop79
Copy link

this worked for me...

brew unlink php

brew link --overwrite php

valet install

@eddy80310
Copy link

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/php@7.1/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/php@7.1/bin/php /usr/local/bin/php

That was the fix on mine.

@orangeShadow
Copy link
Author

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.");
        });

@OZZlE
Copy link

OZZlE commented Jun 2, 2018

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.");
    }

@drbyte
Copy link
Contributor

drbyte commented Sep 19, 2018

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

@mssdef
Copy link

mssdef commented Nov 8, 2018

fixed by:

$ ln -s /usr/local/opt/php@7.0/bin/php /usr/local/bin/php

@AK-PapaSoft
Copy link

My way to fix this was ti rewrite current php version: brew link php@7.1 --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 ;)

@hezll
Copy link

hezll commented Dec 8, 2018

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 php@7.2, but it failed)

@mattstauffer
Copy link
Member

@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!

@andrey-bondarenko
Copy link

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 = 'php@7.2';

@shane-smith
Copy link

shane-smith commented Dec 28, 2018

Hmm, interesting.

brew unlink php@7.1 && brew link php@7.1 --force

Unlinking /usr/local/Cellar/php@7.1/7.1.25... 0 symlinks removed
Linking /usr/local/Cellar/php@7.1/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:

  • brew unlink php@7.2 && brew link php@7.2 --force
  • brew unlink php@7.1 && brew link php@7.1 --force
  • brew unlink php && brew link php --force

Then re-try the valet install command.

@tucq88
Copy link

tucq88 commented Dec 31, 2018

No luck for me :(

@tucq88
Copy link

tucq88 commented Dec 31, 2018

Now it's on line 205 =))

@drbyte
Copy link
Contributor

drbyte commented Dec 31, 2018

@tucq88 please answer the questions I posted above.

@OZZlE
Copy link

OZZlE commented Jan 2, 2019

Hmm, interesting.

brew unlink php@7.1 && brew link php@7.1 --force

Unlinking /usr/local/Cellar/php@7.1/7.1.25... 0 symlinks removed
Linking /usr/local/Cellar/php@7.1/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: #533 (comment)

@mattstauffer
Copy link
Member

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

@mattstauffer
Copy link
Member

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.

@shane-smith
Copy link

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.

@OZZlE
Copy link

OZZlE commented Jan 8, 2019

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.

@mattstauffer
Copy link
Member

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.

@Vinai
Copy link

Vinai commented Jan 28, 2019

Is this out already?

@mattstauffer
Copy link
Member

@Vinai Yep: https://github.com/laravel/valet/releases/tag/v2.1.6

@aado29
Copy link

aado29 commented Feb 28, 2019

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

@frank-f5w
Copy link

frank-f5w commented Apr 15, 2019

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 php@7.2
$ brew link php@7.2
$ valet use php@7.2 (which will restart, too)

@icarojobs
Copy link

Type of @delino12 solve my problem! Thanks dude!

@brianhogg
Copy link

brianhogg commented Sep 1, 2019

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 php@7.3 gives Warning: php@7.2 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.

@drbyte
Copy link
Contributor

drbyte commented Sep 2, 2019

@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.

@pmochine
Copy link

@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

@drbyte
Copy link
Contributor

drbyte commented Oct 22, 2019

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

brew unlink php@7.2
brew link php@7.3

Sometimes adding --force can be useful.

@grafxflow
Copy link

grafxflow commented Nov 25, 2019

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

Example being.

# export PATH="/usr/local/opt/php@7.1/bin:$PATH"
# export PATH="/usr/local/opt/php@7.1/sbin:$PATH"
# export PATH="/usr/local/opt/php@7.2/bin:$PATH"
# export PATH="/usr/local/opt/php@7.2/sbin:$PATH"
export PATH="/usr/local/opt/php@7.3/bin:$PATH"
export PATH="/usr/local/opt/php@7.3/sbin:$PATH"

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

brew unlink php@7.2 && brew link --force php@7.3  

@LeRoyJulian
Copy link

LeRoyJulian commented Nov 30, 2019

After updating to PHP 7.4 :

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

@cuddimatic
Copy link

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 php@7.4 )
brew services restart --all
composer global update
valet start

Hopefully, this helps🙂

@drbyte
Copy link
Contributor

drbyte commented Mar 23, 2020

Im use Valet+ this code bellow help me:
brew unlink valet-php@7.2 && brew link --force valet-php@7.2

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.)

@israelguido
Copy link

Im use Valet+ this code bellow help me:
brew unlink valet-php@7.2 && brew link --force valet-php@7.2

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

sorry!

@AlvinQinwen
Copy link

AlvinQinwen commented Jul 20, 2020

Valet doesn't support PHP version: php@7.4 (try something like 'php7.2' ins tead)
but some vender need php@7.4
how i to do?

@mattstauffer
Copy link
Member

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

@ivansempijja
Copy link

I had the same issue using php 8.3, All the above solutions did not work.
what I had to do was to update valet

composer global update
composer global require laravel/valet
valet install

this should do the trick

@7morimax
Copy link

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.

Funiconó para mi, gracias!

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

No branches or pull requests