Before compiling and installing the PHP GMP extension, please ensure the following requirements are met:
Make sure PHP environment is installed, GMP (GNU Multiple Precision) library is set up, and GCC compiler is ready. If these are missing on your server, please install them first.
Open your terminal and run the following command to clone the PHP source code:
<span class="fun">git clone https://github.com/php/php-src.git</span>
Navigate to the GMP extension directory:
<span class="fun">cd php-src/ext/gmp</span>
Checkout the desired PHP version branch (here PHP 7.4 is used as an example):
<span class="fun">git checkout PHP-7.4</span>
Confirm the current branch with git branch to ensure the correct version is selected.
Generate configuration files by running:
<span class="fun">./buildconf --force</span>
Then configure compilation options to enable the GMP extension:
<span class="fun">./configure --with-gmp</span>
The --with-gmp flag indicates the GMP extension will be compiled and installed.
Run the following to compile the extension:
<span class="fun">make</span>
This process may take a few minutes, please wait patiently.
After compilation finishes, install the extension by executing:
<span class="fun">make install</span>
Then, edit the php.ini configuration file to enable the GMP extension by adding:
<span class="fun">extension=gmp.so</span>
Save and close the configuration file.
Restart the PHP service to apply changes:
<span class="fun">sudo service php-fpm restart</span>
Create a test PHP file with the following content:
<?php
phpinfo();
?>
Access this file through your browser and look for the "gmp" section. If found, the extension is installed successfully.
Following these steps, you have successfully compiled and installed the PHP GMP extension, enabling big integer operations in your PHP applications.
If you encounter issues during installation, check your environment dependencies and error logs to ensure proper configuration.
Wishing you smooth development!