How to install GMP for PHP7 on Ubuntu

PhpUbuntu

Php Problem Overview


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

Php Solutions


Solution 1 - Php

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

Solution 2 - Php

For PHP 7.2:

sudo apt-get install php7.2-gmp

Solution 3 - Php

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

Solution 4 - Php

For PHP 7.4:

sudo apt-get install php7.4-gmp

SO: Ubuntu 20.04

Solution 5 - Php

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

Solution 6 - Php

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

Solution 7 - Php

apt-get install php7.1-gmp

That's it.

Solution 8 - Php

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

Solution 9 - Php

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

Solution 10 - Php

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

Solution 11 - Php

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

Solution 12 - Php

For PHP 7.3 try this.

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

in Ubuntu

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSam MalayekView Question on Stackoverflow
Solution 1 - PhpSam MalayekView Answer on Stackoverflow
Solution 2 - PhpBob RoanView Answer on Stackoverflow
Solution 3 - PhpAles RebecView Answer on Stackoverflow
Solution 4 - PhpNelson MfindaView Answer on Stackoverflow
Solution 5 - PhpTony OkothView Answer on Stackoverflow
Solution 6 - PhpWyattView Answer on Stackoverflow
Solution 7 - PhpanonView Answer on Stackoverflow
Solution 8 - PhpPanoptikView Answer on Stackoverflow
Solution 9 - PhpANIK ISLAM SHOJIBView Answer on Stackoverflow
Solution 10 - PhpTarek AdamView Answer on Stackoverflow
Solution 11 - PhpGanesh KView Answer on Stackoverflow
Solution 12 - PhpKishoreView Answer on Stackoverflow