Home » Php » php – How to install GMP for PHP7 on Ubuntu

php – How to install GMP for PHP7 on Ubuntu

Posted by: admin April 23, 2020 Leave a comment


I was getting the following error when trying to run composer update on a SimpleSAML project.

- openid/php-openid dev-master requires ext-gmp * -> the requested PHP extension gmp is missing from your system.

Running sudo apt-get install php5-gmp did not work and neither did sudo apt-get install php7-gmp

How to&Answers:

To install GMP for PHP7.0 on Ubuntu, run:
sudo apt-get install php7.0-gmp

Make sure your php.ini contains the following:

To find out where your php.ini is located, run:
php --ini


For PHP 7.2:

sudo apt-get install php7.2-gmp


The new way in PHP 7 to install extensions is to just write “php-EXTENSION”
In this case it’s as simple as:

sudo apt-get install php-gmp


apt-get install php7.1-gmp

That’s it.


Thank you it helps me. I use PHP 7.2.
Therefore, I run:

  1. sudo apt-get install php7.2-gmp
  2. extension=php_gmp.so


If you are running php 7.2 and above, then

sudo apt-get install php7.2-gmp

or you can as well install bcmath extension using

sudo apt-get install php7.2-bcmath

I recommend you install both of them, after complete install restart apache

sudo service apache2 reload

sudo service apache2 restart


UPDATE: apt-get has evolved over the years into just apt. On modern systems this will detect the php version, etc.

sudo apt install php-gmp


It’s better to search using package or dependency manager installed in machine.
For yum, you can search using yum search gmp and then install.

yum search gmp

This will yield these search results

Loaded pluginss: extras_suggestions, langpacks, priorities, update-motd
170 packages excluded due to repository priority protections
========================================================= N/S matched: gmp ==========================================================
perl-Math-BigInt-GMP.x86_64 : Math::BigInt::GMP Perl module
python-gmpy2.x86_64 : Python 2 interface to GMP, MPFR, and MPC
gmp.x86_64 : A GNU arbitrary precision library
gmp.i686 : A GNU arbitrary precision library
gmp-devel.x86_64 : Development tools for the GNU MP arbitrary precision library
gmp-static.x86_64 : Development tools for the GNU MP arbitrary precision library
mingw32-gmp.noarch : Cross-compiled GNU arbitrary precision library
mingw64-gmp.noarch : Cross-compiled GNU arbitrary precision library
perl-Math-GMP.x86_64 : High speed arbitrary size integer math
php-gmp.x86_64 : A module for PHP applications for using the GNU MP library

Now install extension with:
yum install php-gmp.x86_64


for centos

sudo yum install php-gmp

for ubuntu

sudo apt install php-gmp

also enable php extension in ini file



For PHP 7.3 try this.

sudo apt-get install php7.-gmp

in Ubuntu