0

I have a dev-server where multiple sites are running in development. Most of them use php8.1

Now for a new project I wanted to run php8.2

According to this answer https://stackoverflow.com/a/54736948/12848667 and several blog posts I found on the internet, I set my composer to a specific php version. But it does not seem to work.

In composer.json:

"config": {
    "optimize-autoloader": true,
    "prepend-autoloader": false,
    "platform": {
        "php": "8.2"
    }
},
"scripts": {
    "php-version": "composer -vvv about"
},

But the output of "php-version" still shows 8.1

$ composer php-version
> composer -vvv about
Running 2.4.4 (2022-10-27 14:39:29) with PHP 8.1.18 on Linux / 5.10.0-22-amd64

what am I missing?

Edit: php8.2 is installed in fpm and cli version

$ which php8.2
/usr/bin/php8.2
user6329530
  • 596
  • 1
  • 7
  • 21

1 Answers1

-1

You need to switch from the default version to the desired one.

  1. Check default version (it should return 8.1)

php -v

  1. Disable PHP 8.1 module (check output to restart any service)

sudo a2dismod php8.1

  1. Enable PHP 8.2

sudo a2enmod php8.2

  1. Set PHP 8.2 as default version

sudo update-alternatives --set php /usr/bin/php8.2

  1. For other PHP extensions, set them as default too

sudo update-alternatives --set phar /usr/bin/phar8.2

  1. restart Apache

sudo systemctl restart apache2

  1. Check if version is defaulted to 8.2

php -v

jmvcollaborator
  • 2,141
  • 1
  • 6
  • 17