jsindos
jsindos

Reputation: 539

Laravel valet using wrong version of PHP

I'm running valet 2.0.5 and it is using the wrong version of PHP. When starting valet I get

$ valet start
Restarting php71...
Restarting nginx...
Valet services have been started.

But phpinfo() gives PHP Version 5.6.30 and Loaded Configuration File: /usr/local/etc/php/5.6/php.ini.

I've installed and relinked php using brew,

$ which php
/usr/local/opt/php71/bin/php

$ php -v
PHP 7.1.7

I've tried uninstalling and reinstalling valet, to no avail.

Upvotes: 4

Views: 5526

Answers (4)

BossNL
BossNL

Reputation: 89

When using the latest version of Valet Linux, you can also isolate a projects' version by running the: valet isolate [email protected] command. Of course, when this is not what you need, scroll down for another solution.

Anyone scrolling by and struggling with this behaviour,I also ran into this and it's very annoying. Especially when we're working on multiple projects that use multiple PHP versions. We need to switch between PHP versions for each project, and if valet use throws errors and you need to change your PHP version constantly, it can drive one nuts. I found this solution to work for me:

Edit the valet bash script under: /home/YOURUSER/.config/composer/vendor/cpriego/valet-linux/valet

scroll to the bottom, where you see the actual php command to run the Valet script, and change it to the desired PHP version it wants. Of course, we can assume that you have multiple PHP versions installed, including the one Valet needs. So like this:

else
    php8.0 "$DIR/cli/valet.php" "$@"
fi

to:

else
    php8.2 "$DIR/cli/valet.php" "$@"
fi

Upvotes: 0

chimit
chimit

Reputation: 588

The old version of PHP (in my case 7.4) was "stuck" for some reason in Valet. Even though php -v returns me php 8.0. The way to force Valet to choose the right version you can use the following command:

valet use [email protected] --force

Upvotes: 11

vuorijv
vuorijv

Reputation: 1

Had a similar problem when upgrading from 7.1 to 7.2.

For me the solution was that I removed the symlinks for php7.1 from /usr/local/opt/

Upvotes: 0

jsindos
jsindos

Reputation: 539

Uncommenting LoadModule php5_module libexec/apache2/libphp5.so in /etc/apache2/httpd.conf did the trick. I don't really know why this worked, but I'm not complaining.

Upvotes: 0

Related Questions