GeoIP not working?

Discussion in 'General' started by 04nunhucks, Mar 30, 2011.

  1. 04nunhucks

    04nunhucks New Member

    Hello, I can't seem to get GeoIP working properly for use with scripts on my server.

    Basically, I've enabled the IP GeoLocation in LS, at server level, and provided the .dat for it. I've also enabled it at VHOST level, and added a GeoIPEnable On directive to the relevant htaccess.

    However, scripts cannot use functions, such as -Call to undefined function- geoip_database_info().

    PHPInfo shows that _SERVER[GEOIP_*] (4 entries) and it's accurate, but I can't seem to get scripts to use the functions. Any ideas?
  2. webizen

    webizen New Member

    You need to add geoip support (download & install pecl geoip, load to lsphp5 ) to lsphp5.
  3. 04nunhucks

    04nunhucks New Member

    Hello webizen, how do I do this?
  4. webizen

    webizen New Member

    Here is the procedure:
    1. download pecl geoip from
    2. build module
      tar zxf geoip-1.0.7.tgz
      cd geoip-1.0.7
      ./configure --with-php-config=/usr/local/lsws/lsphp5/bin/php-config
      make install
      a. you need to install geoip and geoip-devel rpm if not done so (yum install GeoIP-devel).
      b. /usr/local/lsws/lsphp5 is the prefix of running lsphp5.
    3. add line "" to your lsphp5 php.ini file.
    4. restart lsws to make it effective.
  5. 04nunhucks

    04nunhucks New Member

    Thanks webizen!
  6. 04nunhucks

    04nunhucks New Member

    Webizen, when I try to use some functions, as in the code below,

    if (geoip_db_avail(GEOIP_CITY_EDITION_REV1))
    $record geoip_record_by_name("");
    if (
    $record) {
    else {
    "No location found!";
    It doesn't work - the function is just failing.
  7. webizen

    webizen New Member

    Here is what GeoIP can do in LSWS (

    Once you see the $_SERVER[GEOIP_*] variables, GeoIP in LSWS is working properly.

    You are trying to use GeoIP functions ( in PHP which is outside of LSWS. That's why suggestion to add geoip support in lsphp5 is provided. Looks like your GeoDB data file isn't not in the right place. Hence the problem. Copy the GeoIP data file to /usr/share/GeoIP directory to let PHP GeoIP extension pick them up (

    Once done, you can verify which database is available in your system with a script like the following:
    = array(

    foreach (
    $cst as $k=>$v) {
    $k.': '.geoip_db_filename($v).'  '.(geoip_db_avail($v) ? 'Available':'').'<br>';
    Last edited: Mar 31, 2011
  8. 04nunhucks

    04nunhucks New Member

    Hello webizen,

    Thank you very much for the details - it is much appreciated.

    Below's a copy of the output:

  9. DanEZPZ

    DanEZPZ Member

    I assume these instructions are outdated as the path /usr/local/lsws/lsphp5/bin no longer exists.
  10. webizen

    webizen New Member

    As the note(b) indicates, you need to check the prefix of your running lsphp5.
  11. johncaradonnas

    johncaradonnas New Member

    Last Friday I have searched some solutions about magento extensions and I have found Geo-IP lock extension on some websites. But there was some errors on sites but I saw a demo on where it was perfectly.

Share This Page