Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.

Get Started Now!

How to Install and Enable GMP Extension in XAMPP PHP on Linux (Step-by-Step Guide)

Introduction

If you are using XAMPP PHP on a Linux server and encounter errors like:

  • GMP NOT OK
  • Unable to load dynamic library 'gmp'
  • Call to undefined function gmp_init()

then this usually means the GMP extension is not installed, not just disabled.

Many developers assume that uncommenting a line in php.ini is enough—but in XAMPP, that is often not true.

This guide explains why GMP is missing, and shows the correct, production-safe way to compile, install, and enable the GMP extension for XAMPP PHP.


What Is the GMP Extension in PHP?

GMP (GNU Multiple Precision) is a PHP extension used for handling very large integers and high-precision arithmetic.

Common use cases include:

  • Cryptography and security libraries
  • JWT / OAuth / authentication systems
  • Blockchain and hashing operations
  • Keycloak integrations
  • Large integer calculations

Example:

gmp_init("12345678901234567890");

The Real Problem (Why GMP Doesn’t Work in XAMPP)

When you run:

php -m | grep gmp

and get no output, or:

GMP NOT OK

Even after adding this to php.ini:

extension=gmp

❌ Why this happens

XAMPP PHP is a precompiled binary and often does not include gmp.so at all.

So:

  • php.ini only loads extensions
  • It does not create them
  • If gmp.so does not exist, PHP cannot load it

Environment Used in This Guide

  • OS: Linux (Ubuntu based)
  • PHP: XAMPP PHP 8.2.12
  • PHP binary:
/opt/lampp/bin/php
  • php.ini location:
/opt/lampp/etc/php.ini

Step 1: Confirm You Are Using XAMPP PHP

which php
php -v

Expected output:

/opt/lampp/bin/php
PHP 8.2.12

Step 2: Check Whether GMP Is Loaded

/opt/lampp/bin/php -m | grep -i gmp

If nothing appears, GMP is not installed.


Step 3: Check the PHP Extension Directory

/opt/lampp/bin/php -i | grep extension_dir

Example output:

/opt/lampp/lib/php/extensions/no-debug-non-zts-20220829

Check if gmp.so exists:

ls -l /opt/lampp/lib/php/extensions/no-debug-non-zts-20220829 | grep gmp

If nothing is returned, GMP is missing.


Step 4: Install Required Build Dependencies

sudo apt update
sudo apt install -y build-essential autoconf automake libtool \
pkg-config libgmp-dev re2c bison wget

Step 5: Download PHP Source (Same Version as XAMPP)

⚠️ The PHP source version must exactly match your XAMPP PHP version.

cd /tmp
wget https://www.php.net/distributions/php-8.2.12.tar.gz
tar -xzf php-8.2.12.tar.gz

Verify GMP source exists:

ls /tmp/php-8.2.12/ext/gmp

You should see files like gmp.c, config.m4, etc.


Step 6: Compile GMP Extension for XAMPP PHP

cd /tmp/php-8.2.12/ext/gmp

/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config
make -j$(nproc)
sudo make install

This step creates the gmp.so file.


Step 7: Verify gmp.so Was Installed

EXT_DIR=$(/opt/lampp/bin/php -r 'echo ini_get("extension_dir");')
ls -l "$EXT_DIR" | grep gmp

Expected output:

gmp.so

Step 8: Enable GMP in php.ini (Linux)

Open the file:

sudo vi /opt/lampp/etc/php.ini

Important Notes

  • Ignore lines like:
;extension=php_gmp.dll

These are Windows-only.

  • Do not uncomment .dll lines on Linux.

Add this line:

extension=gmp.so

Save and exit:

Esc
:wq

Step 9: Restart XAMPP

sudo /opt/lampp/lampp restart

Step 10: Final Verification

/opt/lampp/bin/php -m | grep -i gmp

Expected output:

gmp

Final confirmation:

/opt/lampp/bin/php -r 'echo function_exists("gmp_init") ? "GMP OK\n" : "GMP NOT OK\n";'

Expected:

GMP OK

🎉 GMP is now fully installed and enabled in XAMPP PHP


Common Mistakes to Avoid

  • Only uncommenting extension=gmp
  • Using .dll extensions on Linux
  • Installing php-gmp via apt for XAMPP
  • PHP version mismatch during compilation
  • Forgetting to restart XAMPP

Conclusion

Enabling GMP in XAMPP PHP on Linux requires more than editing php.ini.
When the extension is missing, compiling it for your exact PHP version is the correct and safe solution.

This method:

  • Does not reinstall PHP
  • Does not reinstall XAMPP
  • Works reliably in production environments

Related Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Artificial Intelligence
0
Would love your thoughts, please comment.x
()
x