53

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

miken32
  • 42,008
  • 16
  • 111
  • 154
Sam Malayek
  • 3,595
  • 3
  • 30
  • 46
  • 2
    What does "did not work" mean? Did apt-get report an error (php7-gmp doesn't exist) or did it install fine but not help (php5-gmp is not used by php7)? The command `apt search php gmp` gives you the list of relevant packages, it suggests that you should install php-gmp if you are using whatever the current default version of PHP is, or php7.0-gmp if you very specifically want to use PHP version 7.0. – Marc Glisse Oct 13 '16 at 05:40
  • Yes. The error was that the package did not exist. Oh `apt search php gmp` would have been a great thing to do. – Sam Malayek Oct 13 '16 at 07:29

12 Answers12

89

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

Make sure your php.ini contains the following: extension=php_gmp.so

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

Sam Malayek
  • 3,595
  • 3
  • 30
  • 46
21

For PHP 7.2:

sudo apt-get install php7.2-gmp
Pang
  • 9,564
  • 146
  • 81
  • 122
Bob Roan
  • 323
  • 3
  • 5
17

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
Zoe
  • 27,060
  • 21
  • 118
  • 148
Ales Rebec
  • 179
  • 1
  • 4
13

For docker based on official php images like php:7.2-fpm

Just add this to Dockerfile

RUN apt install -y libgmp-dev && docker-php-ext-install gmp
Panoptik
  • 1,094
  • 1
  • 16
  • 23
12

For PHP 7.4:

sudo apt-get install php7.4-gmp

SO: Ubuntu 20.04

Nelson Mfinda
  • 139
  • 1
  • 6
7

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

Tony Okoth
  • 157
  • 1
  • 4
6

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
pppery
  • 3,731
  • 22
  • 33
  • 46
Wyatt
  • 61
  • 1
  • 3
5
apt-get install php7.1-gmp

That's it.

Pang
  • 9,564
  • 146
  • 81
  • 122
anon
  • 61
  • 1
  • 1
4

for centos

sudo yum install php-gmp

for ubuntu

sudo apt install php-gmp

also enable php extension in ini file

extension=php_gmp.so
ANIK ISLAM SHOJIB
  • 3,002
  • 1
  • 27
  • 36
3

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

Tarek Adam
  • 3,387
  • 3
  • 27
  • 52
1

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

Ganesh K
  • 639
  • 10
  • 18
-2

For PHP 7.3 try this.

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

in Ubuntu

Kishore
  • 561
  • 9
  • 24