How to enable the PHP GeoIP functions on Debian 5

The geoip_* PHP functions utilise the GeoIP library from Maxmind to geolocate IP addresses to country names. These functions are not enabled by default and this post shows how to enable them for PHP 5 on Debian 5.

Enable GeoIP for PHP 5 on Debian 5

Run the following command as the root user or using the sudo command. These instructions should also work on any Debian derived Linux distro such as Ubuntu.

apt-get install php5-geoip

You’ll then see something along the lines of this:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 12 not upgraded.
Need to get 0B/10.4kB of archives.
After this operation, 41.0kB of additional disk space will be used.
Selecting previously deselected package php5-geoip.
(Reading database ... 50967 files and directories currently installed.)
Unpacking php5-geoip (from .../php5-geoip_1.0.3-1_i386.deb) ...
Setting up php5-geoip (1.0.3-1) ...

At this stage the GeoIP library is now installed but you’ll still need to restart Apache to enable the extension when running scripts via the web server. This is done like so, again running the command as either the root user or using sudo:

/usr/sbin/apache2ctl graceful

My next post looks at how to use the GeoIP functions to look up a country code or name from an IP address.