Spencer Hill
Spencer Hill

Reputation: 1005

Homestead refuses to use specific PHP version (7.1 instead of 8.0)

The Short Version

Laravel application on Homestead is using PHP 8.x as seen in phpinfo(), yet php -v is stating the server is using 7.1 (which is what I want). How is this possible? How do I tell the Laravel application to use 7.1 not 8.x?

The Long Version

I have an older Laravel application (5.8) that I need to upgrade to 8.0. I may be using Shift to do this but I have never done an upgrade manually so I thought I should do that at least once.

So I upgraded Homestead to current (12.x), and everything continued to run fine.

Then I tried to upgrade my PHP version from 7.1 to 8.0 using sudo update-alternatives --config php and chose PHP. Then I verified with php -v that it switched to that version. As expected, I began getting deprecation errors in browser. Knowing I would have to spend some time resolving those I switched back to 7.1... but the errors remained!

I restarted PHP, I restarted the server, I reloaded and reprovisioned the server, I destroyed and reprovisioned the server and absolutely nothing is resolving this issue. I even specified php: "7.1" in the Homestead.yaml file and re-provisioned to no avail.

At this point it seems that the upgrading of Homestead itself is somehow telling PHP to ignore the version I'm specifying it to use. So I know I could downgrade, I suppose, but that isn't really a solution but a band aid. And I'm not certain that will actually work either.

I've tried the Answers in this StackOverflows Change Laravel Homestead v7.0.1 with php 7.2 to php 7.1 including php71.

OS: Windows 10 Homestead: 12.x

This person has an identical problem and resolved it with Docker somehow but I don't understand how to translate that to Homestead.

Upvotes: 1

Views: 539

Answers (1)

Spencer Hill
Spencer Hill

Reputation: 1005

There is PHP-CLI and PHP-web. PHP-CLI version is what is reported when using php -v but PHP-CLI is what NGinx is using, hence getting 8.0 when using phpinfo() in ~/public/index.php

To resolve the issue I manually updated /etc/nginx/sites-enabled/mysite and edited line below location where it says fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; to say fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; and then I restarted PHP with sudo systemctl restart nginx.

Upvotes: 2

Related Questions