简体   繁体   English

Drupal 8 - Commerce Module - BC math PHP 扩展未找到

[英]Drupal 8 - Commerce Module - BC math PHP extension not found

I'm trying to install the commerce module in Drupal 8 however I get the error 'BC math PHP extension not found'.我正在尝试在 Drupal 8 中安装 commerce 模块,但是出现错误“未找到 BC math PHP 扩展”。

I've searched for this problem and tried different things such as editing the PHP.ini by adding 'bcmath.scale=2' however I still get the error message.我已经搜索了这个问题并尝试了不同的方法,例如通过添加 'bcmath.scale=2' 来编辑 PHP.ini,但是我仍然收到错误消息。

Any help would be appreciated, thanks.任何帮助将不胜感激,谢谢。

Just install bcmath plugin for your php version with no need to (re)build php as mentioned on accepted answer只需为您的 php 版本安装bcmath插件,无需(重新)构建 php,如已接受的答案所述

# get php version
php -v

# install bcmath based on your version lets assume php 7.1
# for ubuntu
sudo apt install php7.1-bcmath
# for centos 
yum install bcmath

# restart apache 
sudo systemctl restart apache2

Above problem appears when installing commerce or commerce kickstart using composer使用 composer 安装 commerce 或 commerce kickstart 时出现上述问题

Update 2020 2020 年更新

Please refer to @GiorgosK's answer for installing bcmath via a package manager if you are using a distribution that provides a bcmath package for PHP.如果您使用的是为 PHP 提供bcmath包的发行版,请参阅@GiorgosK 的通过包管理器安装bcmath的答案。 I will ask the OP in comments to update the recommended answer, since that solution is probably what most people need.我会在评论中要求 OP 更新推荐的答案,因为该解决方案可能是大多数人所需要的。

Three years ago when I answered this question, I suggested that you have to rebuild PHP to get bcmath .三年前,当我回答这个问题时,我建议您必须重建 PHP 才能获得bcmath That was incorrect.那是不正确的。 I was using an older distribution of Debian/Ubuntu that provided bcmath as a statically linked extension in the core php package.我使用的是较旧的 Debian/Ubuntu 发行版,它提供bcmath作为核心php包中的静态链接扩展。 I determined at the time (incorrectly) that bcmath was a core extension that had to be enabled at build-time (like SPL and PCRE ).我当时(错误地)确定bcmath是必须在构建时启用的核心扩展(如SPLPCRE )。

For those trying to troubleshoot a missing bcmath extension (such as those building/installing PHP themselves or nevertheless encountering issues), I've corrected and updated my original answer below.对于那些试图对缺少的bcmath扩展进行故障排除的人(例如那些自己构建/安装 PHP 或仍然遇到问题的人),我已经更正并更新了下面的原始答案。 It explains in detail how to troubleshoot a missing PHP extension.它详细解释了如何对丢失的 PHP 扩展进行故障排除。

Original Answer (Corrected)原始答案(更正)

The error message indicates that PHP wasn't built with bcmath support or can't find the installed extension.该错误消息表明 PHP 没有使用bcmath支持构建找不到已安装的扩展。 PHP extensions are either built into PHP directly or they are loaded from an external dynamic library file at runtime. PHP 扩展要么直接内置到 PHP 中,要么在运行时从外部动态库文件加载。

Since PHP obviously doesn't have the extension built-in, it can't find the external library file that provides bcmath .由于 PHP 显然没有内置扩展,因此无法找到提供bcmath的外部库文件。 This file on POSIX platforms will be called bcmath.so and php_bcmath.dll on Windows.这个文件在 POSIX 平台上将被称为bcmath.sophp_bcmath.dll在 Windows 上。

Extension files are installed under a directory indicated by the extension_dir property in php.ini .扩展文件安装在php.ini extension_dir属性指定的目录下。 To determine the value of this property, run the following command:要确定此属性的值,请运行以下命令:

php -r 'echo ini_get("extension_dir").PHP_EOL;'

The default value for this property is configured when PHP is built and may vary from distribution-to-distribution.该属性的默认值是在构建 PHP 时配置的,并且可能因发行版而异。

Once you verify the extension file is installed in this location, you can then check to see if the extension is enabled in php.ini .验证扩展文件安装在此位置后,您可以检查是否在php.ini启用了扩展。 You should see a line that enables the extension like so:您应该看到一行启用扩展名,如下所示:

# POSIX platforms
extension=bcmath.so

# Windows
extension=php_bcmath.dll

For Linux distributions like Ubuntu/Debian that install extensions via the package manager, the format is somewhat different since Debian employs a distributed configuration.对于像 Ubuntu/Debian 这样通过包管理器安装扩展的 Linux 发行版,格式有些不同,因为 Debian 使用分布式配置。 Typically the package manager installs everything correctly, but you can check to see if an ini file exists for bcmath under the corresponding conf.d directory.通常,包管理器会正确安装所有内容,但您可以检查相应的conf.d目录下是否存在bcmathini文件。 These small ini files are snippets imported into the larger php.ini file, and they are typically symlinked to /etc/phpX/mods-available , allowing modules to be initially enabled for all PHP SAPIs such as CLI, CGI, Apache Mod PHP, ETC.这些小的ini文件是导入到更大的php.ini文件中的片段,它们通常被/etc/phpX/mods-available链接到/etc/phpX/mods-available ,允许最初为所有 PHP SAPI 启用模块,例如 CLI、CGI、Apache Mod PHP、等等。 Make sure a symlink exists for the PHP SAPI you need to use.确保您需要使用的 PHP SAPI 存在符号链接。

To ensure your PHP is loading the extension, run phpinfo();为了确保你的 PHP 正在加载扩展,运行phpinfo(); in a test page and search for bcmath .在测试页中搜索bcmath You can also more easily do this with the CLI using a command like:您还可以使用 CLI 使用以下命令更轻松地执行此操作:

$ php -i | grep -i bcmath
# Success output: BCMath support => enabled

# (Another command that works well for checking extensions)
$ php -m | grep -i bcmath
# Success output: bcmath

In order for the CLI to show accurate results, it must target the same php.ini file.为了让 CLI 显示准确的结果,它必须以相同的php.ini文件为目标。 If it doesn't, then use the -c option to temporarily point the CLI at the correct php.ini (ie the one being used by your Drupal site).如果没有,则使用-c选项将 CLI 临时指向正确的php.ini (即您的 Drupal 站点正在使用的那个)。

Add BC MATH extension for PHP 7.2为 PHP 7.2 添加 BC MATH 扩展

If you are getting this ( https://prnt.sc/sehmd5 ) error then, run below command using vagrant ssh如果您收到此 ( https://prnt.sc/sehmd5 ) 错误,请使用 vagrant ssh 运行以下命令

Run these command in root of vagrant ssh在 vagrant ssh 的根目录中运行这些命令

  1. sudo add-apt-repository ppa:ondrej/php须藤添加-apt-repository ppa:ondrej/php
  2. sudo apt update sudo apt 更新
  3. sudo apt install php7.2-bcmath sudo apt 安装 php7.2-bcmath
  4. service apache2 restart服务 apache2 重启
  5. Then open php.ini and search for bcmath然后打开 php.ini 并搜索 bcmath
  6. If bcmath scale is 0, Change it to 2如果 bcmath scale 为 0,则将其更改为 2
  7. Restart php重启php
  8. Restart Apache重启阿帕奇
  9. Hard Reload website硬重新加载网站
  10. Install required modules安装需要的模块

Similarly for any version of PHP, you only need to change PHP version in 3rd command.同样,对于任何版本的 PHP,您只需要在第三个命令中更改 PHP 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM