We did it before but for Nginx (you can look – Installing GeoIP On Nginx). We need this to use GoAcesss log analyzer like tools, Piwik etc. WordPress like modern CMS use PHP based function and needs no server side work. Installing GeoIP Module On Apache2, Ubuntu 16.04 Needs Some Manual Steps After Running Installation Command. Sample PHP file supplied to test.
Installing GeoIP Module On Apache2, Ubuntu 16.04
As there is an Apache Module, installing GeoIP on Apache2 is far easier compared to Nginx. If you run
1 | apt search geoip |
You’ll get libapache2-mod-geoip
apart from other packages. In order to install properly, run :
---
1 2 3 | apt update apt upgrade apt install geoip-bin geoip-database libapache2-mod-geoip libgeoip1 |
In newer Apache, modules automatically get activated, manual work not needed. The Geo files are at this location :
1 | /usr/share/GeoIP/ |
Those files need update by manual works.
You need to download the databases from here :
1 | https://dev.maxmind.com/geoip/legacy/geolite/ |
Do these steps :
1 2 3 4 5 6 7 8 9 10 | cd /usr/share/GeoIP/ ls rm GeoIP.dat wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz gunzip GeoIP.dat.gz wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz gunzip GeoLiteCity.dat.gz wget http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz gunzip GeoIPASNum.dat.gz ls |
The Apache GeoIP Module configuration file is located here :
1 | /etc/apache2/mods-enabled/geoip.conf |
Open it :
1 | nano /etc/apache2/mods-enabled/geoip.conf |
For our above steps, the file after editing should look like this :
1 2 3 4 5 6 | <IfModule mod_geoip.c> GeoIPEnable On GeoIPDBFile /usr/share/GeoIP/GeoIP.dat GeoIPDBFile /usr/share/GeoIP/GeoLiteCity.dat GeoIPDBFile /usr/share/GeoIP/GeoIPASNum.dat </IfModule> |
Save the file. You’ll notice that the file has warning :
1 2 3 | # For performance reasons, it's not recommended to turn GeoIP on serverwide, # but rather only in <Location> or <Directory> blocks where it's actually # needed. |
We are keeping on as we need for works like server log analysis. That module’s documentation is available on GitHub :
1 | https://github.com/maxmind/geoip-api-mod_geoip2 |
The module has hundreds of odd matters, unless you need, keep the status to off. Run configtest and restart the server :
1 2 | apachectl -t sudo systemctl restart apache2.service |
Now, go to your FTP public directory location and wget my script which I kept here on GitHub.Alternatively, you can create a file with some name like geotest.php
and copy-paste this content :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <html> <body> <?php $geoip_country_code = getenv(GEOIP_COUNTRY_CODE); $geoip_country_name = getenv(GEOIP_COUNTRY_NAME); $geoip_region = getenv(GEOIP_REGION); $geoip_city = getenv(GEOIP_CITY); $geoip_postal_code = getenv(GEOIP_POSTAL_CODE); $geoip_latitude = getenv(GEOIP_LATITUDE); $geoip_longitude = getenv(GEOIP_LONGITUDE); echo 'Country code: '.$geoip_country_code.'<br>'; echo 'Country name: '.$geoip_country_name.'<br>'; echo 'Region: '.$geoip_region.'<br>'; echo 'City: '.$geoip_city.'<br>'; echo 'Postal code: '.$geoip_postal_code.'<br>'; echo 'Latitude: '.$geoip_latitude.'<br>'; echo 'Longitude: '.$geoip_longitude.'<br>'; ?> </body> </html> |
Now open URL to point to that file on browser, you will see some information about your ISP like :
1 2 3 4 5 6 7 | Country code: IT Country name: Italy Region: 16 City: Arezzo Postal code: 52100 Latitude: 43.416698 Longitude: 11.883300 |
That means installation is correct.
Tagged With apache geoip error opening file geolitecity dat , Apache Ubuntu geoip , apache2 geoip module , geoip apache module , geoip install apache ubuntu , geoip with apache on ubuntu , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1829 0Gtv_0WshjtJEn5P-dL3HmIwUhrTJiNlFQKKu9d_SfQ9BhQOhQGTq-p1nNgSzigI dd66c0c8232ba2e320e17554b07029074d46a9ce&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , install geoip-bin on Ubuntu , installer mod_geoip apache kubuntu