18

When calling a gmp math function like gmp_mod, I get:

Fatal error: Call to undefined function gmp_mod()

I have installed the php5-gmp package and restarted the web-server, and the function is still undefined. The server is running Ubuntu 10.04 and PHP is running as an Apache module. All software was installed from official packages.

How do I enable the GMP math functions in PHP? I'm looking for a solution that uses official packages, not compiling from source.

26

Here is the way which worked for me :

  1. Installed GMP with apt-get install php5-gmp
  2. Added extension=php_gmp.so to php.ini

Et voilĂ  !

phpinfo() sample :

gmp
gmp support     enabled
GMP version     4.3.2 

It works fine here (Debian), so I suppose it will be ok for Ubuntu too.

| improve this answer | |
  • 2
    On Ubuntu 12.04 LTS, I needed to use gmp.so, not php_gmp.so. I also needed to restart Apache for the changes to take effect (not surprising as I'm using mod_php). – Calrion Jan 26 '14 at 23:52
  • 1
    In my case sudo apt-get install php5-gmp automatically updated php.ini and restarted Apache. – KalenGi Dec 3 '14 at 23:52
  • 5
    For php 7 : apt-get install php7.0-gmp – George D. Aug 3 '16 at 12:19
  • @Benj Can u please tell me, how to install gmp library for php on mac OS? – mohan.gade Apr 19 '17 at 4:31
  • 2
    For the record, for PHP7.1 : apt-get install php7.1-gmp – John Shipp Nov 9 '17 at 21:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.