PHPInfo / Valet - Two different PHP versions
Asked Answered
B

11

13

OK so I am experiencing something quite odd. My phpinfo() shows one version while php -v shows another.

I am running locally on a MacBook Air (Mojave), with Laravel and Valet.

phpinfo():

PHP Version 7.2.13

Configuration File (php.ini) Path   /usr/local/etc/php/7.2
Loaded Configuration File   /usr/local/etc/php/7.2/php.ini
Scan this dir for additional .ini files /usr/local/etc/php/7.2/conf.d

While in my terminal, it shows:

php -v

PHP 7.3.0 (cli) (built: Dec  7 2018 11:00:11) ( NTS )

Now, if I do a which php I get this:

/usr/local/bin/php

In my ~/.bash-profile, I have this:

export "PATH=~/.composer/vendor/bin:$PATH"

I have tried to:

How can I get my actual valet site to use [email protected]?

Bluebird answered 10/12, 2018 at 20:52 Comment(2)
Use php switcher. This helps you to switch php correctly and restart valet.Succinylsulfathiazole
rm ~/.config/valet/valet.sock; valet restart; solved it for me.Wilkes
B
4

Something so basic as rebooting my Macbook solved this issue. Once rebooted, the correct version 7.3 showed in my phpinfo();

Bluebird answered 12/12, 2018 at 8:32 Comment(2)
rm ~/.config/valet/valet.sock; valet restart; solved it for meWilkes
@Chk I got a 'Bad gateway' on the Valet site after this command. valet install solved it for me.Iso
W
46

Below simple fix worked for me.

rm ~/.config/valet/valet.sock
valet restart 
Wilkes answered 24/7, 2020 at 21:47 Comment(8)
Worked like a charm for me - Thanks @Chk!Inveteracy
Works good but I seem to need to repeat this every now and then (perhaps after restarting my computer), is there a permanent solution?Westfall
worked on ubuntu too, just a different path, at least on my machine, rm ~/.valet/valet.sockAustraloid
Not sure why I lose this configuration after restarting and have to do it again and again, anyone else?Mixon
Would love to know how to fix this so it doesn't keep happening.Jesseniajessey
This should be added into the valet library as restart command as wellOrgy
Removing the valet sock resulted in a 502 Bad Gateway after restart.Gerhard
@Gerhard I think you will need to run valet install in this case, refer to #53838155Gottuard
C
6

In my case it worked after forcing the specific PHP version:

valet use [email protected] --force
Cherin answered 9/6, 2021 at 14:54 Comment(0)
K
5

Good news, please upgrade to latest valet version, you can easily switch php version. Source: https://laravel.com/docs/5.8/valet

PHP Versions

Valet allows you to switch PHP versions using the valet use php@version command. Valet will install the specified PHP version via Brew if it is not already installed:

valet use [email protected]

valet use php   //without any specification, it will be using latest version
Kc answered 13/8, 2019 at 13:20 Comment(0)
B
4

Something so basic as rebooting my Macbook solved this issue. Once rebooted, the correct version 7.3 showed in my phpinfo();

Bluebird answered 12/12, 2018 at 8:32 Comment(2)
rm ~/.config/valet/valet.sock; valet restart; solved it for meWilkes
@Chk I got a 'Bad gateway' on the Valet site after this command. valet install solved it for me.Iso
F
3

From MacBook pro (Mojave), with Laravel and Valet:

valet use [email protected]
Flanker answered 20/10, 2019 at 2:30 Comment(1)
Welcome to SO! When you post an answer, eve if it is ok, try to explain your answer a little bit. If it is a new point of view, show Pros and Cons. I already edit your answer, but the official language on SO is english, there is another SO on Spanish.Cenozoic
T
3

To be able to effectively change the version of php on my machine I use the following script:

Add to your user's .bash_profile
Then use the following command to switch

switch-php7.x

switch-php() {
  valet stop
  brew unlink [email protected] [email protected] [email protected]
  brew link --force --overwrite php@$1
  brew services restart php@$1
  composer global update
  rm -f ~/.config/valet/valet.sock
  valet install
}

https://gist.github.com/r1tt3r/e0f199eb274d5ff186b73956af594316

Taskwork answered 27/1, 2021 at 16:41 Comment(0)
V
3

I am running linux valet on Ubuntu 20.04 , The following command works for me

valet use 8.0

Here, 8.0 refers to the php version.

Vengeance answered 15/3, 2021 at 1:23 Comment(1)
you save my day . ThanksWhiffen
P
2

Basically the php valet uses and the one used by your macbook is different. But as already mentioned by @Shiro and @Israel Alexis Palma Quezada, in newer versions valet use php73 would solve your problem. If it's not working, try running composer global update to update your global packages, thus updating valet

To update the mac php version, execute the following lines:

export PATH="your/path/to/[email protected]/bin:$PATH"
export PATH="your/path/to/[email protected]/sbin:$PATH"

or simply add these two lines to your ~/.profile or ~/.bash_profile

Don't forget to run source ~/.profile or source ~/.bash_profile or whatever file you chose to edit.

Perloff answered 8/4, 2020 at 12:31 Comment(1)
composer global update did it!Petuu
L
2

NB: Tested this solution on Ubuntu 20.04 Desktop

If you are using Valet Linux Plus(Has more features than Valet Linux) Just do valet use {your PHP version} --update-cli. For instance to use php8.0 just run:

valet use 8.0 --update-cli

This will update both php-fpm version plus php-cli version too.

Lawford answered 14/2, 2022 at 6:28 Comment(0)
T
0

Yesterday I encountered the same problem on Ubuntu 18.

At first I changed the PHP version:

$ sudo a2dismod php7.2
$ sudo a2enmod php7.3
$ sudo update-alternatives --set php /usr/bin/7.3

But valet was still showing the wrong PHP version. Rebooting did not work. In fact, phpinfo() was displaying PHP 7.1.

After run ps -aux | grep php I noticed few instances of php-fpm (5.6, 7.1 and 7.2) running.

I stopped them

$ sudo service php5.6-fpm stop
$ sudo service php7.1-fpm stop
$ sudo service php7.2-fpm stop

Then started 7.3

$ sudo service php7.3-fpm start

And now my phpinfo() display the correct version of PHP

Thorite answered 12/12, 2018 at 8:43 Comment(0)
A
0

I ran into this same problem while using valet plus today. When I switched PHP versions it was showing the previous one in my browser but the correct one in my terminal. Looking at the my brew services list:

brew services list

It showed that one of the valet-php services ([email protected]) was not in the service list but somehow my valet was able to switch to it. Valet didn't install this PHP properly and that's what was causing the issue. I did the following to uninstall that PHP and reinstall it with brew.

brew uninstall [email protected]
sudo rm -rf /usr/local/Cellar/[email protected]/7.2.34_1
brew install [email protected]

The PHP version that was once not showing in the brew services list now showed and I was able to "stop" that php version's service:

brew services stop [email protected] 

which made everything work properly again without a restart.

Athens answered 14/10, 2020 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.