Update GeoIP2/GeoLite2 databases from your PHP script or automatically via Composer.
- PHP 8.3+
ext-curlext-zip(only required for CSV database editions)- A valid MaxMind license key
composer require neto737/geoip2-updateAdd the configuration to your project's composer.json. The databases will be checked and updated every time composer update or composer update neto737/geoip2-update runs.
{
"scripts": {
"post-update-cmd": "neto737\\GeoIP2Update\\ComposerClient::run"
},
"extra": {
"neto737\\GeoIP2Update\\ComposerClient::run": {
"license_key": "YOUR_LICENSE_KEY",
"dir": "@composer/../geoip2"
}
}
}The @composer token is replaced with the directory of your composer.json file.
use neto737\GeoIP2Update\Client;
$client = new Client([
'license_key' => 'YOUR_LICENSE_KEY',
'dir' => '/path/to/geoip2',
'editions' => ['GeoLite2-ASN', 'GeoLite2-City', 'GeoLite2-Country'],
]);
$client->run();
foreach ($client->updated() as $message) {
echo $message . PHP_EOL;
}
foreach ($client->errors() as $error) {
echo 'Error: ' . $error . PHP_EOL;
}$client = new Client([
'geoipConfFile' => '/etc/GeoIP.conf',
'dir' => '/path/to/geoip2',
]);
$client->run();The GeoIP.conf file is the standard MaxMind configuration format:
AccountID 12345
LicenseKey YOUR_LICENSE_KEY
EditionIDs GeoLite2-ASN GeoLite2-City GeoLite2-Country
| Option | Type | Description |
|---|---|---|
license_key |
string |
Your MaxMind license key |
dir |
string |
Directory where database files will be stored |
editions |
string[] |
List of edition IDs to update (see below) |
geoipConfFile |
string |
Path to a GeoIP.conf file (sets license_key and editions) |
| Edition ID | Format |
|---|---|
GeoLite2-ASN |
MMDB |
GeoLite2-City |
MMDB |
GeoLite2-Country |
MMDB |
GeoIP2-ASN |
MMDB |
GeoIP2-City |
MMDB |
GeoIP2-Country |
MMDB |
GeoLite2-ASN-CSV |
ZIP |
GeoLite2-City-CSV |
ZIP |
GeoLite2-Country-CSV |
ZIP |
GeoIP2-ASN-CSV |
ZIP |
GeoIP2-City-CSV |
ZIP |
GeoIP2-Country-CSV |
ZIP |
CSV editions require ext-zip.
MIT — see LICENSE.