The GeoIP extension allows you to find the location of an IP address, including the city, state, country, latitude, and longitude.
To install this extension on PHP 7.0, 7.1, 7.2, 7.3, or 7.4, run the following commands as your server's root user:
sudo apt-get -y install gcc make autoconf libc-dev pkg-config sudo apt-get -y install libgeoip-dev sudo pecl7.X-sp install geoip-beta
Once installed, create a configuration file for the extension and restart PHP by running the following command as root:
sudo bash -c "echo extension=geoip.so > /etc/php7.X-sp/conf.d/geoip.ini" sudo service php7.X-fpm-sp restart
To install this extension on PHP 5.4, 5.5, or 5.6, run the following commands as your server's root user:
sudo apt-get -y install gcc make autoconf libc-dev pkg-config sudo apt-get -y install libgeoip-dev sudo pecl5.X-sp install geoip
Once installed, create a configuration file for the extension and restart PHP by running the following command as root:
sudo bash -c "echo extension=geoip.so > /etc/php5.X-sp/conf.d/geoip.ini" sudo service php5.X-fpm-sp restart
You can check that the extension was installed with this command:
phpX.Y-sp -i | grep geoip
The output will look like this:
$ php7.1-sp -i | grep geoip /etc/php7.1-sp/conf.d/geoip.ini, geoip geoip support => enabled geoip extension version => 1.1.1 geoip library version => 1006000 geoip.custom_directory => no value => no value
To uninstall this extension, as root run the commands:
sudo rm /etc/phpX.Y-sp/conf.d/geoip.ini sudo peclX.Y-sp uninstall geoip
Next, restart PHP-FPM with the command:
sudo service phpX.Y-fpm-sp restart