skip to Main Content

I’m new to Laravel and decided to take the route of Homestead, setting up Vagrant and getting familiar with something other than WAMP.

After a bit of confusion and a learning curve, I’ve gotten everything working, projects connected, loading and I am now familiar with Vagrant and moving my way around. Everything is great… Until I try to upgrade from Laravel 8 to 9.

In an effort to so, I have my composer.json file as such:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^9.0",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5"
    },
    "require-dev": {
        "spatie/laravel-ignition": "^1.0",
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.3.3"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi"
        ],
        "post-root-package-install": [
            "@php -r "file_exists('.env') || copy('.env.example', '.env');""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "platform": {
            "php": "8.0.2"
         }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

Despite all seeming correct, I get the following error when I try to update via composer update

[ErrorException]
  Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are run
  ning 7.4.9.

I run a check:

C:localdevLaravel>php --version
PHP 7.4.9 (cli) (built: Aug  4 2020 11:52:41) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Sure enough it’s correct. HOWEVER – If I echo out my PHP version on my website, I am getting 8.0.9.

If I check my version in phpmyadmin, same thing – PHP 8.0.9.

Let’s check Vagrant itself…

vagrant@homestead:~$ php --version
PHP 8.0.9 (cli) (built: Jul 30 2021 13:03:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies

I should also add that I have WAMP server on my machine that handles some WordPress projects. I had that running on PHP 7.4.9… AH HA! I thought… Changed the version on WAMP to 8.0.9 – no luck, same result.

What gives? Why am I unable to change my PHP version (or better yet, how?) for my Laravel projects?

2

Answers


  1. You need to edit your Homestead.yaml file you can specify your php version there

    sites:
    - map: site-name.test
      to: /path/to/your/site
      type: Laravel
      php: "8.1"
    

    if however you need to change the CLI php version you need to ssh into your vagrant box and run

    sudo update-alternatives --config php
    

    you can then select a php version to use

    Login or Signup to reply.
  2. following on what Futureweb mentioned, I had to force my PHP version in the Homestead.yaml file and then run:

    vagrant reload --provision
    

    I then managed to get it working.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search