Composer refuses to install because a PHP extension is missing
Your 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.
Fix it fast
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 bcmath2Match what you see, then jump to its fix
- 1
php -m prints nothing for the extension name.The extension is not enabled for the CLI PHPFix - 2
php -v shows a version other than the one you changed.Composer runs under a different PHP than you configuredFix - 3
composer 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
- 1
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 bcmath2Fix
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=bcmath3Verify
The extension is listed and Composer resolves again.
php -m | grep -i bcmath
composer installConfirmed by php.net
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-reqs2Fix
Run Composer with the PHP you configured, or point the PHP command at that version.
/usr/bin/php8.3 /usr/local/bin/composer install3Verify
Run the check for that binary and see the extension.
/usr/bin/php8.3 -m | grep -i bcmathConfirmed by getcomposer.org
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-reqs2Fix
Skip only that extension, and run check-platform-reqs on the real server as part of the deploy.
composer install --ignore-platform-req=ext-bcmath3Verify
On the real server, the check reports every requirement as success.
composer check-platform-reqsConfirmed by getcomposer.org
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
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack 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 fixBack 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 fixBack end
CodeIgniter 3 stops with "Your system folder path does not appear to be set correctly"
503 Service Unavailable
CodeIgniter 3's front controller resolves $system_path and then checks that the result is a directory.
3 causes, each with a fix