I am upgrading a system from PHP 7.4 to 8.1 using as base Ubuntu 22.10.
In the old image, we are using php7.4-geoip
, but this package doesn’t exist in PHP 8.1.
JavaScript
x
apt install php8.1-geoip
Unable to locate package php8.1-geoip
What is the procedure to migrate to a newer version?
Advertisement
Answer
This package isn’t available yet, however you can install via composer.
Ensure GeoIP is installed on the machine:
JavaScript
apt install -y geoip-bin geoip-database
geoipupdate -v
Install via PHP Composer:
JavaScript
curl -sS https://getcomposer.org/installer | php
php composer.phar require geoip2/geoip2:~2.0
Quick test script to ensure it’s all working:
JavaScript
<?php
require_once 'vendor/autoload.php';
use GeoIp2DatabaseReader;
$geoip = new Reader('/usr/share/GeoIP/GeoLite2-City.mmdb');
$reader = $geoip->city('12.87.118.0');
echo "I should be United States.... ".$reader->country->name."n";
Output:
JavaScript
root@cc19c55aedef:/# php test-geoip.php
I should be United States . United States