"The requested PHP extension bcmath is missing from your system."
Asked Answered
H

16

68

Greetings fellow developers,

I am trying to use composer for a PHP project of mine on a development server I recently booted up and for some reason I am unable to. I successfully installed composer, however, when I try to run the require command I get the following error:

root@webserver:/var/mypersonal/index# composer require php-amqplib/php-amqplib
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_openssl.dll' - /usr/lib/php/20151012/php_openssl.dll: cannot open shared object file: No such file or directory in Unknown on line 0
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Using version ^2.6 for php-amqplib/php-amqplib
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - php-amqplib/php-amqplib v2.6.3 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
    - php-amqplib/php-amqplib v2.6.2 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
    - php-amqplib/php-amqplib v2.6.1 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
    - php-amqplib/php-amqplib v2.6.0 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
    - Installation request for php-amqplib/php-amqplib ^2.6 -> satisfiable by php-amqplib/php-amqplib[v2.6.0, v2.6.1, v2.6.2, v2.6.3].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.0/cli/php.ini
    - /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
    - /etc/php/7.0/cli/conf.d/10-opcache.ini
    - /etc/php/7.0/cli/conf.d/10-pdo.ini
    - /etc/php/7.0/cli/conf.d/20-calendar.ini
    - /etc/php/7.0/cli/conf.d/20-ctype.ini
    - /etc/php/7.0/cli/conf.d/20-exif.ini
    - /etc/php/7.0/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.0/cli/conf.d/20-ftp.ini
    - /etc/php/7.0/cli/conf.d/20-gettext.ini
    - /etc/php/7.0/cli/conf.d/20-iconv.ini
    - /etc/php/7.0/cli/conf.d/20-json.ini
    - /etc/php/7.0/cli/conf.d/20-mysqli.ini
    - /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
    - /etc/php/7.0/cli/conf.d/20-phar.ini
    - /etc/php/7.0/cli/conf.d/20-posix.ini
    - /etc/php/7.0/cli/conf.d/20-readline.ini
    - /etc/php/7.0/cli/conf.d/20-shmop.ini
    - /etc/php/7.0/cli/conf.d/20-sockets.ini
    - /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.0/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.0/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.0/cli/conf.d/20-tokenizer.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, deleting ./composer.json.

I'm assuming it's something to do with the PHP warning I recieve right when running the composer require command but no google search results lead me to the correct direction.

Additionally, I have provided my /etc/php/7.0/cli/php.ini file incase of an error in that file.

https://gist.github.com/anonymous/bc5bac59d684cbf575cef931ef36daf6 (I couldn't include the file in this post due to the character limit on posts.)

Herbalist answered 12/7, 2017 at 6:2 Comment(0)
I
102

You can use function get_loaded_extensions to see if bcmath modul is loaded. Or in terminal php -m or php -m | grep name_of_the_modul

You can install it depending on what OS you are using:

Ubuntu

sudo apt install php7.0-bcmath

CentOS

yum install bcmath

Ivanivana answered 12/7, 2017 at 6:7 Comment(1)
Just a note on installing it, if you run php -v you can check which version of PHP you're running. Mine was PHP 7.1.8-1ubuntu1. As I'm using 7.1, it had to install php7.1-bcmath instead.Southerner
C
29

PHP 7.2

Debian - jessie

apt-get update

apt-get install php7.2-bcmath

work like a charm :)

Contemporaneous answered 4/12, 2018 at 17:57 Comment(1)
working for me, we just need to change the version of php and package name in command line code as per the requirement. Ex. sudo apt install php7.3-mbstringNowhither
G
16

If you are using Docker:

  • bcmath can be installed by running this command inside a container: docker-php-ext-install bcmath
Gilboa answered 11/3, 2020 at 11:56 Comment(0)
P
15

In Ubuntu 20.04

For php 7.4.3, sudo apt install php7.4-bcmath

Parkerparkhurst answered 23/5, 2020 at 18:42 Comment(0)
C
14

For any version in php Centos use

This solution worked for me

yum install php-bcmath

PHP will take the default version installed in the machine, search for that package and install it.

Delete the file composer.lock file if that is already created and then run again,

composer install

If you run

composer update

it will update whatever default packages are installed in composer.json which might create problem for you.

Centuple answered 5/4, 2018 at 14:34 Comment(0)
P
12

For PHP 7.1, the following worked for me:

sudo apt install php7.1-bcmath
Petronille answered 12/5, 2018 at 21:28 Comment(0)
P
9

check your php version by type: php --version

you will see something like this:

PHP 7.2.9-1+ubuntu16.04.1 ....

then sudo apt install phpX.X-bcmath where X.X is php version, so for this ^ example it will be sudo apt install php7.2-bcmath

after this check if module existed or not by type php -m | grep bcmath

Prober answered 21/8, 2018 at 0:18 Comment(0)
E
8

php 7.2 if you have other version just change it accordingly

For CentOS

sudo yum install php72-bcmath

For Ubuntu

sudo apt install php7.0-bcmath
Elutriate answered 22/3, 2019 at 7:1 Comment(2)
for php 7.2 sudo apt install php7.2-bcmathMothball
for php 7.4 sudo apt install php7.4-bcmathPopedom
S
6

Run this command, hope it will works

sudo apt-get install php-bcmath
Splinter answered 4/11, 2019 at 17:52 Comment(0)
S
5

hope this will fix the problem.

sudo apt install php-bcmath

Shores answered 29/11, 2018 at 9:59 Comment(0)
R
2

Strange thing here
Some month ago I have installed all PHP version in the same manner. In here are the 4 identically configured version of php: 5.6, 7.0, 7.1, 7.2, with the same extensions ( when this was made possible ).
The strange thing was that bcmath is present for all php version excluding 7.1.
In the solution search I arrive here in this question, where the logic's things was confirmed installing bcmath, but in my Linode Debian 9 server the command apt install php7.1-bcmath doesn't work, with 3 error messages;

  • E: Impossible to find the package php7.1-bcmath
  • E: Impossible to find some package with glob "php7.1-bcmath"
  • E: Impossible to find a package with the regular expression "php7.1-bcmath"

The goals no meet with any combination of tips and trick, refreshing apt cache, change Debian's mirrored server, installing yum, so on...

After some tentatives I had an illumination: modificating of /etc/apt/sources.list enabling the default Linode repository, then after an apt update (with no solution in the immediate), I have restored the /etc/apt/sources.list commenting out the Linode mirror sources again. Magically, after the new apt update the command now are working.

By this I confirm: apt install php7.1-bcmath is the right command, but your Debian can need a kick in the ass

Robedechambre answered 10/9, 2018 at 14:11 Comment(1)
Couldn't find any package by glob 'php7.1-bcmath'Eliathan
P
2

Note: This will work on Ubuntu servers.

Start by navigating to the server's root directory:

/

Install a particular PHP version, for example, PHP 7.4, by specifying it in the package name:

sudo apt-get install php7.4-bcmath

After successfully installing the package, restart your Apache web server to activate the changes:

sudo service apache2 restart

Prejudicial answered 10/10, 2023 at 8:38 Comment(0)
O
1

Install with this command, thats work for me

apt-get install php-bcmath
Oralle answered 29/4, 2022 at 11:51 Comment(0)
E
0

I tried below package and it worked in Php version 5.6

yum install php56w-bcmath
Enrapture answered 7/2, 2018 at 3:44 Comment(0)
O
0

For those who have already tried installing bc-math and still composer is giving errors.

Try this command

rm composer.lock

It will definitely work

Ornamental answered 14/3, 2022 at 17:43 Comment(0)
D
0

A simple apt-get install php-bcmath does the trick for php 8.3

Deportation answered 17/7 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.