8

I'm getting the following error while installing one of a joomla component.

Function : bcmod is not available. Please ask your hosts how you can enable this function in your PHP installation.

madhead
  • 31,729
  • 16
  • 153
  • 201
Chillu
  • 113
  • 1
  • 1
  • 6
  • 5
    I would suggest asking your hosting company how you can enable that function in your PHP installation. – Madbreaks May 16 '12 at 20:37
  • An emulation of the `bcmath` functions is available in *upgradephp*, using the commandline `dc` utility as fallback (= slow). – mario May 16 '12 at 21:04

4 Answers4

12

you need your PHP to be compiled with bcmath support (--enable-bcmath configure option). If you're on shared hosting it is unlikely they will enable it for you. So you can try a solution from PHP manual from this page: http://ru.php.net/manual/en/function.bcmod.php I haven't tried it , but you can test it:

/** 
 * my_bcmod - get modulus (substitute for bcmod) 
 * string my_bcmod ( string left_operand, int modulus ) 
 * left_operand can be really big, but be carefull with modulus :( 
 * by Andrius Baranauskas and Laurynas Butkus :) Vilnius, Lithuania 
 **/ 
function my_bcmod( $x, $y ) 
{ 
    // how many numbers to take at once? carefull not to exceed (int) 
    $take = 5;     
    $mod = ''; 

    do 
    { 
        $a = (int)$mod.substr( $x, 0, $take ); 
        $x = substr( $x, $take ); 
        $mod = $a % $y;    
    } 
    while ( strlen($x) ); 

    return (int)$mod; 
} 

// example 
echo my_bcmod( "7044060001970316212900", 150 ); 
Alexey
  • 3,414
  • 7
  • 26
  • 44
  • thanks alexey. i have a dedicated server and i have full control over it. where to configure bcmod function. do i need to specify in php.ini file? – Chillu May 16 '12 at 23:29
  • you should recompile your php as stated here: http://ru.php.net/manual/en/bc.installation.php This is done by specifying --enable-bcmath to configure script. In order to not miss any other options you have in your current PHP binary, you can create a phpinfo(); page and copy configure string from there, add --enable-bcmath and recompile then – Alexey May 17 '12 at 10:36
  • 1
    Since you mention you have a dedicated server, you may just be able to install php-bcmath (or something named similarly) with whatever package manager your distro offers. I ended up with the same error when attempting to use the neo4j-php-ogm package with Symfony. If you installed PHP via your package manager, search your default repos for the module before you go building PHP from source to enable bcmath. – Ethan Hohensee Nov 02 '17 at 02:36
  • 1
    I am using it to check the IBAN banking number.as suggested in https://stackoverflow.com/questions/20983339/validate-iban-php. And it works perfectly. – Martin G Feb 12 '18 at 20:01
3

You can install the bcmath package using installer. I am using CentOS so my commands are relatively different. You can use according to your OS.

yum install php-bcmath

Once you install the package,

If you are using php-fpm then you need to restart php-fpm service using

systemctl restart php-fpm

You need to restart http server at last

systemctl restart nginx
Prabhu
  • 178
  • 2
  • 12
  • It differs from on different php versions. For ex. on php 8.1 it can be used: apt-get install php8.1-bcmath on php 5.6: apt-get install php5.6-bcmath – Aak Apr 02 '23 at 15:46
1

If you have a dedicated server, try the solution given here https://stackoverflow.com/a/25229386/8015825.

Before recompiling, check the php.ini file and search for "bcmath". You may find bcmath.scale=0. If so, change the 0 to a 2.

And then restart your http server

m50
  • 766
  • 8
  • 11
0

Is needed install the library at Debian 10, also to do remove expired key of the repository before to install the bcmath

apt-key list 2>/dev/null | grep expired -B 1
apt-key del 95BD4743
apt-key list | grep expired
wget -O /etc/apt/trusted.gpg.d/deb.sury.gpg https://packages.sury.org/php/apt.gpg
apt-get update
apt install php7.2-bcmath
systemctl restart apache2
Doberon
  • 611
  • 9
  • 19