Error updating Docker PHP version for WP-CLI

Hi there,

I have a DevKinsta local site setup using php8.0. When I try to use WP-CLI I am getting errors saying I’m using php7.4.

So I found & followed instructions here:
(I am also using roots/sage and have acorn installed as an MU plugin)

But I’m getting errors in my Terminal after selecting the php version:

www-data@eb548f61a27c:/www/kinsta/public/mysite$ update-alternatives --config php
There are 5 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php8.1   81        auto mode
  1            /usr/bin/php7.2   72        manual mode
  2            /usr/bin/php7.3   73        manual mode
* 3            /usr/bin/php7.4   74        manual mode
  4            /usr/bin/php8.0   80        manual mode
  5            /usr/bin/php8.1   81        manual mode

Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/php8.0 to provide /usr/bin/php (php) in manual mode
update-alternatives: error: error creating symbolic link '/etc/alternatives/php.dpkg-tmp': Permission denied

Please advise so that I can use WP-CLI :pray:

Many thanks!
Gareth

Hello Gareth :wave:

Thank you for reporting it here.
As I could see from the report/error, it seems due to the “User Permission” issue as per that message:

update-alternatives: error: error creating symbolic link '/etc/alternatives/php.dpkg-tmp': Permission denied

I noticed that you ran that update-alternatives --config php command line with the user:
www-data

I suspect you might be connecting to the local containr/Docker with this command perhaps?

docker exec -it devkinsta_fpm sudo -H -u www-data bash

If that so, please try the following steps instead:

  1. Connect to the local FPM container with:
    docker exec -it devkinsta_fpm bash
    (so it will be using the default root user instead of www-data user)

  2. In the FPM container, type:
    update-alternatives --config php

  3. Select the PHP version from the list (and enter), and done.
    The PHP version should be changed properly now.

Please give it a try and let me know if it works for you.

Cheers,
Agus

Works perfectly, thanks Agus!
Gareth

Awesome!
thank you for the update and glad to hear it works perfectly Gareth! :+1:

Cheers,
Agus