Faking Platform Requirements in Composer or How to Get ext-imagick Installed on an 1&1/Ionos Managed Server

For a project I need to install a php package on an 1&1/Ionos managed webserver that requires ext-imagick.

Imagick is a native php extension to create and modify images using the ImageMagick API.

ImageMagick is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF.

The requirement is nested in another required php package so as soon as I attempt to install the package via composer, it will fail.

Depending on the objected outcome, there are two ways to solve that.

Let's say I don't need the image processing at all, then I can skip the requirement check.

Ignore Platform Requirements on Command-Line

Run the following command

composer install --ignore-platform-reqs

and composer won't check if the PHP version and required extensions are met. Doesn't mean that the software will run afterwards, but it gets downloaded and installed.

--ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib- and `ext-`) and force the installation even if the local machine does not fulfill these. See also the platform config option.

-- https://getcomposer.org/doc/03-cli.md#install-i

Since Composer 2.0 it's possible to ignore specific parts with --ignore-platform-req=php eg.

Ignore Requirements in composer.json

A better way to skip the test for platform requirements is the config.platform option in composer.json.

There you put in the exact version of the extension (or PHP version) to fulfill the requirements of a package and then you are good to go.

{
  "require": {
    // requirements
  },
  "config": {
    "platform":{
      "ext-imagick": "3.4.4"
    }
  }
}

This is especially helpful when the composer commands are automated and you can't add the cli arguments.

Bonus, Polyfill ext-imagick

Since Ionos Webserver offers access to ImageMagick through the commandline, it's possible to install the polyfill calcinai/php-imagick to get at least basic image processing functions.

{
  "require": {
    "calcinai/php-imagick": "dev-master"
  },
  "config": {
    "platform":{
      "ext-imagick": "3.4.4"
    }
  }
}

In case you want to extend the polyfill, because your software package uses more extensive imagick methods, you can fork the package, set the calcinai/php-imagick version to "dev-feature" and point it to your repository. (Don't forget to open a pull request for the original package.)

  {
    "require": {
      "calcinai/php-imagick": "dev-feature"
    },
    "config": {
      "platform":{
        "ext-imagick": "3.4.4"
      }
    },
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/marcus-at-localhost/php-imagick"
      }
    ]
  }

That's it. Took me a while to find out, but knowing that is quite a super power.