GMP error on IPBlock run
Hi, today I installed the rlanvin/php-ip package via composer. Alongside that I also added the 'ext-gmp' to my composer.json:
"require": {
"php": "^8.1",
"ext-gmp": "*",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.18",
"laravel/tinker": "^2.7",
"league/flysystem-aws-s3-v3": "^3.0",
"rlanvin/php-ip": "^3.0",
"s1lentium/iptools": "^1.1",
"spatie/laravel-ignition": "^1.3",
"spatie/laravel-json-api-paginate": "^1.12"
},
I added a call to the IPBlock like this:
$block = IPBlock::create($subnet->network.'/'.$subnetPrefix); but upon running I get this error message:
{
"message": "Call to undefined function PhpIP\\gmp_init()",
"exception": "Error",
"file": "/var/www/html/vendor/rlanvin/php-ip/src/IP.php",
"line": 196,
"trace": [
{
"file": "/var/www/html/vendor/rlanvin/php-ip/src/IP.php",
"line": 145,
"function": "initGmpFromString",
"class": "PhpIP\\IP",
"type": "::"
},
Is there anyone who knows what I've done wrong, or if this is just a bug in the package?
Are you sure you have the gmp extension enabled in your php.ini? (And perhaps also restarted apache/php-fpm)
The gpm_init function is defined by the gmp extension. https://www.php.net/manual/en/function.gmp-init
Also note that the ext-gmp requirement is only checked during the execution of the composer CLI which means only the PHP CLI's extensions are checked. If you are running multiple PHP versions and e.g. use php-fpm with a different PHP version for development purposes, you need to ensure that the extension is installed for that PHP version as well.