skip to Main Content

I am creating a WordPress plugin but need to connect to Xero’s API. Xero suggest using the composer plugin xero-php-oauth2 so I setup my WP plugin to use composer, which works. And I have successfully installed and used phpdotenv as a test.

Unfortunately I am getting the following error:

Fatal error: Composer detected issues in your platform: Your Composer  dependencies require a PHP version ">= 8.1.0". You are running  8.0.28. in  /var/www/html/wp-content/plugins/tws-eta-api-visualisations/vendor/composer/platform_check.php  on line 24

Composer seems to think that I my PHP version is 8.0.28 when I am running 8.1.17 and I cannot figure out why.

I am configuring both PHP and composer with a Nix flake:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in {
        devShell = with pkgs; pkgs.mkShell {
          buildInputs = [
            php81
            php81.packages.composer
            nodejs-16_x
            (yarn.override { nodejs = nodejs-16_x; })
          ];

          shellHook = ''
            if [ ! -d "vendor" ]; then
              ${php81}/bin/php ${php81.packages.composer}/libexec/composer/composer.phar update
              composer install
            fi

            if [ ! -d "node_modules" ]; then
              yarn install --immutable
            fi

            yarn build

            open http://localhost:8000
          '';
        };
      }
    );
}

Does anyone know what I can do to resolve my flake?

I have tried following various guides online about setting Composer’s PHP version via config updates, install commands, and composer.phar.

2

Answers


  1. Chosen as BEST ANSWER

    This may not be relevant for all, but this is what was happening for me.

    I was running my WordPress instance in Docker, and Docker set their PHP version to 8.0.28...

    So while my Nix flake was correctly setting the PHP version, after the files were transferred to Docker, it was using Dockers PHP version.

    Updating the docker-compose WordPress image to image: wordpress:6.0-php8.1-apache has resolved this for me.


  2. Your answer sounds like a legit solution to me, especially as you use the same PHP version for development and production.

    If it diverges, like the scenario in question, you can also tell via the Composer configuration (composer.json) what the platform looks like so that Composer takes that for the platform instead of the platform.

    E.g. in the flake you go to PHP 8.2, in composer.json you tell Composer to still resolve the dependencies to PHP 8.1 as you did not yet migrate the docker container as you first want to test your flake configuration for development only.

    I have no clue thought how to tell via flake to only use that setting in composer.json during the production build and not during the development build.

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