您的系统缺少所需的PHP扩展bcmath。

67

各位开发者,你们好:

我正在尝试在最近启动的开发服务器上为我的 PHP 项目使用 composer,但不知何故无法使用。我已经成功安装了 composer,但是当我尝试运行 require 命令时,出现以下错误:

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.

我猜测这与我在运行composer require命令时收到的PHP警告有关,但是没有谷歌搜索结果指向正确的方向。

此外,我提供了我的/etc/php/7.0/cli/php.ini文件,以防该文件出现错误。

https://gist.github.com/anonymous/bc5bac59d684cbf575cef931ef36daf6 (由于帖子的字符限制,我无法在此帖中包含该文件。)

16个回答

99

您可以使用函数get_loaded_extensions来查看是否加载了bcmath模块。或者在终端中输入php -mphp -m | grep name_of_the_modul

根据您所使用的操作系统不同,您可以进行如下安装:

Ubuntu

sudo apt install php7.0-bcmath

CentOS

yum install bcmath


7
关于安装的注意事项,如果您运行php -v,可以查看您正在使用的PHP版本。我的版本是PHP 7.1.8-1ubuntu1。由于我正在使用7.1版本,所以需要安装php7.1-bcmath。 - Alex L

29

PHP 7.2

Debian - jessie

apt-get update

apt-get install php7.2-bcmath

运作得非常好 :)


1
对我来说有效,我们只需要根据要求更改命令行代码中的PHP版本和软件包名称。例如:sudo apt install php7.3-mbstring。 - Akhilesh Kumar

15

在Ubuntu 20.04中

对于php 7.4.3,sudo apt install php7.4-bcmath


15

如果您正在使用 Docker:

  • bcmath 可以通过在容器内运行以下命令进行安装:docker-php-ext-install bcmath

14

对于任何使用php Centos的版本,请使用以下解决方案:

这个解决方案对我有用:

yum install php-bcmath

PHP会使用机器上安装的默认版本,查找该包并安装它。

如果已经创建了composer.lock文件,请删除该文件,然后再运行以下命令:

composer install

如果您运行以下命令:

composer update

它将更新在composer.json中安装的默认包,这可能会给您带来问题。


12

对于PHP 7.1,以下内容适用于我:

sudo apt install php7.1-bcmath

9

通过输入php --version检查您的php版本。

您将看到以下类似内容:

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

然后执行sudo apt install phpX.X-bcmath,其中X.X是php版本号,以此例为例,应该执行sudo apt install php7.2-bcmath

执行完毕后,通过输入php -m | grep bcmath来检查模块是否存在。


8

如果你使用的是其它版本的php,只需要相应地进行更改。

对于 CentOS 操作系统:

sudo yum install php72-bcmath

对于 Ubuntu

sudo apt install php7.0-bcmath

7
对于 PHP 7.2,请执行以下命令安装 sudo apt install php7.2-bcmath - Benjamin Gakami
对于 PHP 7.4,运行以下命令安装 bcmath 扩展:sudo apt install php7.4-bcmath - Koustav

6

运行此命令,希望它能正常工作。

sudo apt-get install php-bcmath

5

希望这能解决问题。

sudo apt install php-bcmath


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接