如何安装bcmath模块?

71

如何在服务器上安装bcmath模块?我尝试了

yum update php-bcmath

但它说它什么也没找到。


https://github.com/phpseclib/bcmath_compat 可能是值得考虑的一个选项。 - neubert
19个回答

70

尝试使用yum install php-bcmath命令安装。如果还找不到,可以使用yum search bcmath查找软件包名称。


嗨,我尝试了这个更新,但它没起作用。不过,我在谷歌上搜索并发现CentOS没有适用于我的服务器上的PHP版本的BCMath模块。因此,我计划寻找其他替代方案。谢谢。 - JDesigns
好的,我假设你使用Fedora操作系统了……在你的问题中说明你所使用的发行版会很有帮助。 - greg0ire
CentOS Linux 6.0(最终版)具有php-bcmath。 - Kinjal Dixit
由于一些冲突,我不得不选择 yum install php53u-bcmath - Kenny Wyland
12
在PHP7中,执行sudo apt install php7.0-bcmath命令安装bcmath扩展。 - insign
这对我有用。Yum自动检测到了我正在使用的php版本的正确软件包。 - TPHughes

68

Ubuntu和PHP7.1

sudo apt install php7.1-bcmath

没有版本规范的Ubuntu和PHP

sudo apt install php-bcmath

7
使用sudo apt-get install php7.0-bcmath命令安装php7.0-bcmath。 - CGray
你如何在Mac上安装它? - Eric Luo
4
如果使用Apache,则需要在执行完命令后运行“service apache2 reload”。否则,bcmath 将无法启用。 - jdhildeb
我遇到了一些服务器,其中yum需要在软件包名称末尾添加CPU架构,例如php71-bcmath.x86_64。使用yum search bcmath查看您的服务器上有哪些选项可用。 - thirdender

12
yum install php72-php-bcmath.x86_64
cp /etc/opt/remi/php72/php.d/20-bcmath.ini /etc/php.d/
cp /opt/remi/php72/root/usr/lib64/php/modules/bcmath.so /usr/lib64/php/modules/
systemctl restart httpd

不确定为什么我要深入了解,考虑到 yum install 已经在 phpinfo() 中给了我 bcmath 模块。


1
因为您需要php-bcmath(基础包,来自remi-php72),而不是php72-php-bcmath(来自remi-safe的SCL)。 - Remi Collet
这个解决方案对我有用。我是新手。有人可以详细解释一下吗?或者提供一个链接,让我可以看到更多细节。 - Ahmed Numaan

11

在CentOS 6.5上表现良好

yum install bcmath

在apache重启后,我所有对bcmath函数的调用都开始正常工作了

service httpd restart

太棒了!


8

3
非常感谢!我已经五年多没有使用 PHP 了,但是后来我开始在所有项目中使用 Docker。我不得不挖掘一个非常古老的项目,并且试图添加随机的 PPA 和 deb 包,花了几个小时来尝试使用 PECL 和一堆其他东西。由于你的帮助,Composer 安装终于成功了! - ChristianTL

6

报错信息为“调用未定义的函数bcmod()”

yum install php-bcmath
systemctl restart httpd.service

然后您应该在phpinfo下看到类似于/etc/php.d/bcmath.ini的内容。

Centos 7
Plesk 12
PHP 5.4.16

4
如果你已经安装了 php 7.1,那么这行代码将在你的系统上正常工作。
sudo apt install php7.1-bcmath

Ubuntu 16.04 系统中检查您的 PHP 版本。

php -v

然后结果会显示在那里...

PHP 7.1.x+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Aug 19 2018 07:16:12) ( NTS )版权所有 (c) 1997-2018 The PHP Group Zend Engine v3.2.0, 版权所有 (c) 1998-2018 Zend Technologies 带有Zend OPcache v7.2.9-1+ubuntu16.04.1+deb.sury.org+1,版权所有 (c) 1999-2018,由Zend Technologies提供


4
以下内容是我在使用Remi软件仓库时,基于CentOS 7.4和PHP 7.1所采用的方法。
首先,查找我的PHP版本:
[kiat@reporting ~]$ php --version
PHP 7.1.33 (cli) (built: Oct 23 2019 07:28:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies

然后在remi-php71存储库中搜索bcmath扩展:

[kiat@reporting ~]$ yum search php71 | grep bcmath
php71-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
php71u-bcmath.x86_64 : A module for PHP applications for using the bcmath

现在安装第一个匹配的扩展:

[kiat@reporting ~]$ sudo yum --enablerepo=remi-php71 install php-bcmath
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00
.
.
.

最后,重新启动 PHP 和 Nginx:

[kiat@reporting ~]$ sudo systemctl restart php-fpm nginx

3

我发现包含该软件包的仓库未启用。在OEL7上,

$ vi /etc/yum.repos.d/ULN-Base.repo
Set enabled to 1 for ol7_optional_latest

$ yum install php-bcmath

然后那个方法起作用了...

我使用以下命令查找包的位置

$ yum --noplugins --showduplicates --enablerepo \* --disablerepo \*-source --disablerepo C5.\*,c5-media,\*debug\*,\*-source list \*bcmath

在 Debian 上工作过。 - Kaymaz

3
如果您想启用任何扩展,则首先必须安装该扩展。可能已启用扩展但未安装,因此以bcmath为例:
  1. yum search php-bcmath

  2. 然后确保您要安装此扩展的php版本

  3. 您将得到类似于yum search命令之后的输出>>

yum search php-bcmath** 加载插件:fastestmirror、universal-hooks 从缓存的主机文件中加载镜像速度

EA4: 66.71.244.18
cpanel-addons-production-feed: 66.71.244.18
base: mirror.nodesdirect.com
epel: mirror.coastal.edu
extras: www.gtlib.gatech.edu
nux-dextop: mirror.li.nux.ro
updates: mirror.jaleco.com
**============================================================== N/S matched: php-bcmath ===============================================================
ea-php54-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php55-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php56-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php70-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php71-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php72-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
  1. 如果我想安装php71,则命令将类似于yum install ea-php71-php-bcmath.x86_64或yum install php71-bcmath。

  2. 您可以从以上步骤安装任何扩展。


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