maxmind / GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
https://maxmind.github.io/GeoIP2-php/
Apache License 2.0
2.34k stars 279 forks source link

How to install GeoIP2 for dummies #110

Closed dark-rider closed 6 years ago

dark-rider commented 6 years ago

I use GeoIP legacy database with PHP for years, without any trouble. Just ony little folder containing the following files, and that's it:

geoip.inc
geoipcity.inc
geoipregionvars.php
GeoIPCity.dat

Then just a short PHP code to use:

include("../geoip/geoipcity.inc");
include("../geoip/geoipregionvars.php");
$gi = geoip_open("../geoip/GeoIPCity.dat",GEOIP_STANDARD);
$geoip_record = geoip_record_by_addr($gi,$my_ip_address);
$my_geoip_string = $geoip_record->city."/".$GEOIP_REGION_NAME[$geoip_record->country_code][$geoip_record->region]."/".$geoip_record->country_code;
geoip_close($gi);

Now you announce GeoIP2 to replace GeoIP (legacy) soon, which unfortunately is much more complicated for low-level PHP coders who have never heared of things like Composer, dependencies, PHAR and so on. I also have no dedicated web server nor SSH, but just a shared hosting account with PHP and an FTP account to upload files from my Windows PC to the webspace.

Could you publish a low level, very easy instruction how to make GeoIP2 running for dummies who have no idea of GitHub and who are not able to understand all the concepts behind?

Moreover: As I read in another posting, GeoIP2 is running significantly slower then legacy version, that's why you recommend the optional C plugin. Can this be installed on shared hosting accounts, and if so, how?

dark-rider commented 6 years ago

With installed PHAR PHP extension (and even my shared hoster has it), it's extremely simple to install GeoIP2: Just download the latest geoip2.phar file from MaxMind's releases page on GitHub, copy it to your webspace and include it to your PHP scripts by require 'geoip2.phar';. Then you can use the code as in MaxMind's examples. I don't understand why MaxMind strongly recommends using Composer which is much more complicated especially if you did not yet use Composer.

oschwald commented 6 years ago

I am glad you figured out how to use the Phar. Composer is a more robust solution for managing dependencies, which is why we recommend it. You don't need to run it on your shared host; you can just upload the vendor directory.

alipour66m commented 6 years ago

how can I find vendor diretory?

nchelluri commented 6 years ago

Hi @alipour66m,

We recommend installing using Composer which should create a vendor directory. Instructions can be found here: https://github.com/maxmind/GeoIP2-php#install-via-composer