Installing geoip php library and geoip standard on OS X 10.7 (Lion) for use with MAMP using PECL and Homebrew

I needed to install the GeoIP library for use on a PHP Application, so i tried to download the libraries from MaxMind website, i found that to be little to none helpful, having had experience with libraries and MAMP i started to wonder what is the best way to install this?, my initial idea was spot on! PECL,
i had to first find the version of PECL bundled with MAMP, this isn’t really hard just locate your PHP Version (5.3.6 for me) then try to locate it under MAMP’s Application folder


rroche at Ramon-Roches-MacBook-Pro in /Applications/MAMP/bin/php/php5.3.6
$ la
total 32
drwxr-xr-x 8 rroche admin 272 Dec 5 12:01 .
drwxr-xr-x 5 rroche admin 170 Sep 29 16:34 ..
drwxr-xr-x 14 rroche admin 476 Nov 28 16:54 bin
drwxr-xr-x 5 rroche admin 170 Dec 5 12:37 conf
drwxr-xr-x 39 rroche admin 1326 Dec 5 12:05 include
drwxr-xr-x 4 rroche admin 136 Sep 29 16:34 lib
drwxr-xr-x 3 rroche admin 102 May 25 2011 modules

your php utitlies are located under bin/ so my absolute PECL path is located under

/Applications/MAMP/bin/php/php5.3.6/bin/pecl

Installing GeoIP from Homebrew

So the actual db needs to be installed, luckily for us someone already created a brew formula for this

rroche at Ramon-Roches-MacBook-Pro in /Applications/MAMP/bin/php/php5.3.6/include/php
$ brew install geoip

as easy as that, the PECL installer will take care of the rest

Installing GeoIP PHP libraries from PECL

once I had located PECL I tried searching and installing GeoIP

rroche at Ramon-Roches-MacBook-Pro in ~/
$ /Applications/MAMP/bin/php/php5.3.6/bin/pecl search geoip

Retrieving data…0%
Matched packages, channel pecl.php.net:
=======================================
Package Stable/(Latest) Local
geoip 1.0.8 (stable) 1.0.8 Map IP address to geographic places

$ /Applications/MAMP/bin/php/php5.3.6/bin/pecl install geoip

Only to find it fail under some missing php dependencies located under /Applications/MAMP/bin/php/php5.3.6/include/php
which on my setup where missing, a quick Google search and I found that i had to download the MAMP Component Zip file from MAMP main site ( you can find the download section here http://www.mamp.info/en/downloads/index.html )
once you downloaded locate the php source zip that relates to what you are using, in my case php-5-3-6.zip (or something similar), unzip it and if your php folder is named php-5-3-6 rename it to simply php then move it to

/Applications/MAMP/bin/php/php5.3.6/include

once there go to the php directory you just moved

cd /Applications/MAMP/bin/php/php5.3.6/includes/php

you will need to configure php to create some directories you will need

rroche at Ramon-Roches-MacBook-Pro in /Applications/MAMP/bin/php/php5.3.6/include/php
$ ./configure
$ (.. all the config verbose ..)

once you have done that, you can try to install geoip from PECL again this time it wont fail, (in my case I had to do `sudo` I’m not sure if this is due to something I previously did I tend to play with my folder permissions and owners)

rroche at Ramon-Roches-MacBook-Pro in /Applications/MAMP/bin/php/php5.3.6/include/php
$ /Applications/MAMP/bin/php/php5.3.6/bin/pecl install geoip

at the end of the installation process you will notice it warns you about adding a reference to the geoip extension to your php.ini file

extension=geoip.so

open MAMP then go to File -> Edit Template -> PHP -> PHP 5.3.6 and add the following almost at the very end

[geoip]
extension=geoip.so

only followed by

; DONT REMOVE: MAMP PRO php5.3.6.ini template compatibility version: 1

Now restart apache, from MAMP just Stop and Start the services, and you will be all done.



2 Responses to “ “Installing geoip php library and geoip standard on OS X 10.7 (Lion) for use with MAMP using PECL and Homebrew”

  1. simon says:

    thank you ramon, i appreciate your help.
    was really useful your guide. now I’m trying to do it

  2. admin says:

    Thanks Simon let me know how it goes.

Leave a Reply