• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Installing GeoIP Module On Apache2, Ubuntu 16.04

By Abhishek Ghosh June 8, 2017 8:51 pm Updated on June 8, 2017

Installing GeoIP Module On Apache2, Ubuntu 16.04

Advertisement

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

 

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

Vim
1
apt search geoip

You’ll get libapache2-mod-geoip apart from other packages. In order to install properly, run :

Advertisement

---

Vim
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 :

Vim
1
/usr/share/GeoIP/

Those files need update by manual works.

You need to download the databases from here :

Vim
1
https://dev.maxmind.com/geoip/legacy/geolite/

Do these steps :

/usr/share/GeoIP/
Vim
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 :

Vim
1
/etc/apache2/mods-enabled/geoip.conf

Open it :

Vim
1
nano /etc/apache2/mods-enabled/geoip.conf

For our above steps, the file after editing should look like this :

Vim
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 :

Vim
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 :

Vim
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 :

Vim
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 :

Vim
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 :

Vim
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
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Installing GeoIP Module On Apache2, Ubuntu 16.04

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • How To Configure Nginx Access Log With GeoIP (Ubuntu 16.04)

    Here is How To Configure Nginx Access Log With GeoIP on Ubuntu 16.04. Usage Commands Also Shown. Access Log is Powerful & Configurable Tool.

  • Install Piwik on nginx on Ubuntu 14.04 on Rackspace Cloud

    Here are all the needed commands to install piwik on nginx on Ubuntu 14.04 on Rackspace Cloud Server with GeoIP PECL and GeoIP PHP modules.

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy