Drupal 8 - Commerce Module - BC math PHP extension not found - drupal-8

I'm trying to install the commerce module in Drupal 8 however I get the error 'BC math PHP extension not found'.
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.
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
# 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

Update 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. I will ask the OP in comments to update the recommended answer, since that solution is probably what most people need.
Three years ago when I answered this question, I suggested that you have to rebuild PHP to get 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. I determined at the time (incorrectly) that bcmath was a core extension that had to be enabled at build-time (like SPL and PCRE).
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. It explains in detail how to troubleshoot a missing PHP extension.
Original Answer (Corrected)
The error message indicates that PHP wasn't built with bcmath support or can't find the installed extension. PHP extensions are either built into PHP directly or they are loaded from an external dynamic library file at runtime.
Since PHP obviously doesn't have the extension built-in, it can't find the external library file that provides bcmath. This file on POSIX platforms will be called bcmath.so and php_bcmath.dll on Windows.
Extension files are installed under a directory indicated by the extension_dir property in php.ini. 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.
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. 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. 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. 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. Make sure a symlink exists for the PHP SAPI you need to use.
To ensure your PHP is loading the extension, run phpinfo(); in a test page and search for bcmath. You can also more easily do this with the CLI using a command like:
$ 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. If it doesn't, then use the -c option to temporarily point the CLI at the correct php.ini (i.e. the one being used by your Drupal site).

Add BC MATH extension for PHP 7.2
If you are getting this (https://prnt.sc/sehmd5) error then, run below command using vagrant ssh
Run these command in root of vagrant ssh
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.2-bcmath
service apache2 restart
Then open php.ini and search for bcmath
If bcmath scale is 0, Change it to 2
Restart php
Restart Apache
Hard Reload website
Install required modules
Similarly for any version of PHP, you only need to change PHP version in 3rd command.

Related

Cakephp : intl extension missing

I am trying to install CakePHP 3.8 in my mac ( macos high sierra version 10.13.6), but i had this problem since yesterday tell me that extension intl is missing from your system
User-iMac:TEST zakaria$ composer create-project --prefer-dist
cakephp/app my_app_name
Installing cakephp/app (3.8.0)
- Installing cakephp/app (3.8.0): Loading from cache
Created project in my_app_name
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
- cakephp/cakephp 3.8.1 requires ext-intl * -> the requested PHP
extension intl is missing from your system.
- cakephp/cakephp 3.8.0 requires ext-intl * -> the requested PHP
extension intl is missing from your system.
- Installation request for cakephp/cakephp 3.8.* -> satisfiable
by
cakephp/cakephp[3.8.0, 3.8.1].
To enable extensions, verify that they are enabled in your .ini
files:
- /etc/php.ini
You can also run `php --ini` inside terminal to see which files
are
used by PHP in CLI mode.
User-iMac:TEST User$
i tried to uncomment extension=php_intl.dll in php.ini
i tried to add extension=intl.so
And so many solutions out there but nothing seems to work
Unfortunately, Intl extension is missing on native instalation of PHP 7.1.24 on Mac OS high sierra.
Download PHP 7.1 from php.net, install XCode Command Line Tools, ICU (http://site.icu-project.org/), Autoconf, reinstall the developer tools header files, and finally install Intl extension using phpize.
Important: you'll have to disable SIP.

'.' is not recognized

I was following this tutorial for aws-php sdk Tutorial.
I Installed composer manually by using Composer-Setup.exe.
So when I am trying to install composer by clicking composer.json>Composer>install
this error appeared.
And if you have some proper tutorial for using php-sdk, please comment it here.
The tutorial is 2years outdated.
What you are trying to do is execute composer.
The correct way to execute composer in a windows based system is:
php composer.phar install
or
c:\path\to\php php composer.phar install
The approach of using ./ works with linux based systems after you have made the file executable. You generally do not require that in windows.
Go through the following links for details:
https://www.codementor.io/php/tutorial/composer-install-php-dependency-manager
https://www.codementor.io/php/tutorial/composer-install-php-dependency-manager

How to install pecl memcached extension on wamp?

I need to install memcached for my windows 64bit wamp running on localhost. My specific php version is 5.5.12.
I am using version 2.2.0 of the extension found here:
http://pecl.php.net/package/memcached
How do I install the extension as it is a .tgz file?
I tried finding a working dll for this extension without any success.
Step 1:
Check in your PHP’s extension directory (like: C:\wamp64\bin\php\php5.6.25\ext) if not exists file php_memcache.dll, go to the page http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/
to download this file (depends on your PHP version) and put php_memcache.dll in your directory C:\wamp64\bin\php\php5.6.25\ext
Step 2:
Edit your file php.ini, add this line:
extension=php_memcache.dll
Step 3: restart apache
and check now your phpinfo

Putty Codes for servers

This is first time I'm working with Putty.very interesting
I want, how to install apache,php for new web-server via Putty.
rpm -qa | grep apache
rpm -qa | grep php
Those codes are how to find apache,php version for old web-server
i have some idea about those codes, But i don't know meaning of those codes
tar vxzf libssh2-1.4.2.tar.gz
cd libssh2-1.4.2
./configure
make
make install
Is this correct way to install apache,php for new web-server via Putty?
For the production servers installations YaST2 is better than putty.
because putty we have to includes codes and paths ,YaST2 is like normal windows software installation process.
We have to set path YaST2 then it works correctly.

How to download a file with MSYS?

I would like to download a script from a vanilla MSYS environment.
On Linux, I would do
wget <url>
On Mac OS X, I would do
curl -O <url>
Unfortunately, neither of these alternatives appear to be available in a default installation of MSYS. I have also tried using the LPW::Simple module in Perl, but that also seems to not come installed by default.
Are there any tools that come with a default MSYS environment that can be used to accomplish this?
I could always tell the end-user to download the file themselves, but that defeats the goal of having everything "just work" with a minimal need for installing additional software.
There is an MSYS wget package, but it doesn't seem to be installed by default. If you are willing to modify the MSYS environment, your script can do:
mingw-get install msys-wget-bin