Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Composer refuses to install because a PHP extension is missing

ErrorYour requirements could not be resolved to an installable set of packages.

Short answer

Composer checks the PHP that runs it, not the PHP your web server uses. Enable the extension for that PHP binary, then run composer again. Only if you cannot install it locally, skip the check for that one extension with --ignore-platform-req, and never in production.

  • Applies to Composer 2.8, PHP 8.3, PHP 8.4, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the PHP that Composer uses which extensions it has and which ini files it reads. The two answers split the causes below.

    php -v
    php --ini
    php -m | grep -i bcmath
  2. 2Match what you see, then jump to its fix

    1. 1php -m prints nothing for the extension name.The extension is not enabled for the CLI PHPFix
    2. 2php -v shows a version other than the one you changed.Composer runs under a different PHP than you configuredFix
    3. 3composer install runs on a build machine, while production already has the extension.You cannot install it here, but the extension exists where the app runsFix

What does the error look like?

  • Your requirements could not be resolved to an installable set of packages.
  • The requested PHP extension bcmath * is missing from your system.
  • Install or enable PHP's bcmath extension.

Cause 1 of 3

The extension is not enabled for the CLI PHP

1Check

The web server and the command line often load different configuration. php --ini shows the file the command line reads. The web server PHP can have the extension while this one does not.

php --ini
php -m | grep -i bcmath

2Fix

Install the extension package for the same PHP version, or uncomment its line in the ini file shown by php --ini. On Ubuntu with the ondrej or distro packages the package is named after the version.

sudo apt install php8.3-bcmath
# or edit the loaded file and enable:
# extension=bcmath

3Verify

The extension is listed and Composer resolves again.

php -m | grep -i bcmath
composer install

Confirmed by php.net

Did this fix it?

Cause 2 of 3

Composer runs under a different PHP than you configured

1Check

Several PHP versions can be installed side by side. Composer uses whichever php is first in PATH, so enabling the extension for another version changes nothing.

which php
php -v
composer check-platform-reqs

2Fix

Run Composer with the PHP you configured, or point the PHP command at that version.

/usr/bin/php8.3 /usr/local/bin/composer install

3Verify

Run the check for that binary and see the extension.

/usr/bin/php8.3 -m | grep -i bcmath

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 3

You cannot install it here, but the extension exists where the app runs

1Check

Composer lets you skip the check for one named extension. It also offers a platform setting that makes Composer resolve against a faked environment. Both hide real gaps, so confirm the target server has the extension first.

composer check-platform-reqs

2Fix

Skip only that extension, and run check-platform-reqs on the real server as part of the deploy.

composer install --ignore-platform-req=ext-bcmath

3Verify

On the real server, the check reports every requirement as success.

composer check-platform-reqs

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Keep the CLI and web PHP versions identical on a server, and check php --ini after an upgrade.
  • List needed extensions under require in composer.json (for example ext-bcmath) so the problem shows on the first install.
  • Run composer check-platform-reqs in your deploy script on the target machine.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Back end

CodeIgniter 3 loads the model but the property is undefined

The model name you are loading is the name of a resource that is already being used: user

CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.