How to Install bcmath extension of PHP on CentOS

BCMath is a PHP extension that provides arbitrary precision mathematics functions, including basic operations like addition, subtraction, multiplication, and division, with support for numbers of any size and precision. If you need to work with numbers that exceed the limits of the standard floating-point numbers, BCMath is an excellent option.

In this guide, we will walk you through the process of installing BCMath on CentOS, a popular Linux distribution widely used for server deployments. We will assume that you already have PHP installed and running on your server.

Step 1: Update the system packages

Before we start the installation process, it is essential to update the system packages to their latest versions. Run the following command to do so:

sudo yum update

Step 2: Install the required dependencies

BCMath extension requires the GNU Multiple Precision Arithmetic Library (GMP) to be installed on your system. Run the following command to install GMP:

sudo yum install gmp gmp-devel

Step 3: Install the BCMath extension

Now that we have installed the necessary dependencies, we can proceed to install the BCMath extension. Run the following command:

sudo yum install php-bcmath

After the installation is complete, restart the PHP service:

sudo systemctl restart php-fpm

Step 4: Verify the installation

To ensure that the installation was successful, you can create a PHP file and run the following code:

echo bcadd("1000000000000000000000", "0.0000000000000000000001", 50);

The above code will output the sum of two numbers, one being a very large number, and the other being a very small number. If the output is correct, then the BCMath extension is installed correctly and working.

See also  How to Configure PostgreSQL to Listen from Any IP Address on CentOS 6.2

Commands Mentioned:

  • sudo yum update – updates the system packages to their latest versions.
  • sudo yum install gmp gmp-devel – installs the GNU Multiple Precision Arithmetic Library and its development files.
  • sudo yum install php-bcmath – installs the BCMath extension for PHP.
  • sudo systemctl restart php-fpm – restarts the PHP service.


In this guide, we have demonstrated how to install the BCMath extension for PHP on CentOS. With the BCMath extension, you can perform arithmetic operations on numbers of arbitrary precision, making it an excellent tool for scientific or financial applications. By following the steps outlined above, you should now have the extension installed and working correctly on your CentOS system. If you encountered any issues or have any suggestions for improving this guide, please feel free to leave a comment below.


Leave a Reply

Your email address will not be published. Required fields are marked *