Home > Net >  Composer issues when running mPDF in PHP 7.4
Composer issues when running mPDF in PHP 7.4

Time:08-21

I get the following error when running mPDF in my browser. I have just installed the latest version of mPDF on my cloud server running PHP 7.4. The requirements page for mPDF say I should be able to run this version with PHP 7.3 I have tried to resolve the issue in composer.json but have no success. I am not able to install PHP 8.0 without upgrading the hosting which I do not want to do. Any direction is appreciated.

Error message: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0".

CodePudding user response:

If you would like to learn why the php package is required (this may sound stupid, but think about it as a requirement with a specific version), you can make use of composer-depends(1), a.k.a. why?:

$ composer why php
...
composer/semver                        3.2.6       requires  php (^5.3.2 || ^7.0 || ^8.0) 
doctrine/annotations                   1.13.2      requires  php (^7.1 || ^8.0) 
...

It gives an alphabetical listing of packages in your configuration and which php version they require. This should help you to spot which package requires ^8.0.0 / >= 8.0.0 to get a better understanding.


When your target platform has PHP 7.4, you can configure your project to always depend on that version. This works by specifying the platform php version as a configuration option.

Get the exact php version on your target platform, e.g. 7.4.30 (Aug 2022).

Note: PHP 7.4.x is going to end of life this year[1], consider upgrading the hosting within the next two months to 8.0 at least (if changing hosting for the PHP version is hard, consider to already go to 8.1, test your project with each version first thought, best done locally).

Then within your project configure that version as the projects target platform version:

$ composer config platform.php 7.4.30 # (1.)
# (no output)

1. replace the exemplary version 7.4.30 with your target platform version

After changing the Composer project configuration this way, you need to update the projects dependencies:

$ composer update
# ...

Now Composer will no longer infer the available version of the php platform package (the PHP version) from the environment but instead take the configured platform version. Your local PHP version is not interfering any longer to resolve the installable set of packages. Instead, the configured platform PHP version is used for the resolution.

This effectively prevents that you pull in packages that require a higher PHP version.

Commit all changes to the configuration (composer.json) and pinned versions (composer.lock) and use those to do the packaging for the deployment to the target platform.

  • Related