Install geoip module on bitnami lamp and lightsail


Purpose:

In this specific article, we will show different content based on country.

Technology:

In this specific article, I will focus on Bitnami LAMP. It actually provides a complete development and production environment for PHP. 

LAMP stands for Linux, Apache, MySQL/MariaDB and PHP. For more details, you can follow this article.

Reason:

Below are few reasons for using Bitnami LAMP in this article.
  1. Widely use.
  2. AWS Lightsail gives native support to Bitnami LAMP.
  3. No clear documentation or article on the internet regarding the above two requirements.

Installation:

1. modules Insallation:

Run the following command in your SSH to install the necessary modules.

sudo apt-get update
sudo apt-get install build-essential libtool autoconf unzip wget
sudo apt-get install libgeoip-dev
cd ~/
wget "https://github.com/maxmind/geoip-api-mod_geoip2/archive/refs/tags/1.2.10.tar.gz"
tar -xf 1.2.10.tar.gz
cd geoip-api-mod_geoip2-1.2.10/
sudo apxs -i -a -lGeoIP -c mod_geoip.c

2. Enable module:

Enable the GeoIP module by adding the below text in the very end of /opt/bitnami/apache/conf/httpd.conf.

GeoIPEnable On

3. GeoIP-database Installation:

Just run the below command to install the geoip-database. This database stores information of all the IPs like the country name and city name etc.

sudo apt-get install geoip-database

4. Restart Apache:

Restart apache by running below command

sudo /opt/bitnami/ctlscript.sh restart apache


5. Add or change .htaccess

Now make a change in your htaccess file as per your requirements. 
My requirement is, that if the IP of the visitor is from Vietnam then I redirect to https://example.com/en/.

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(VN)$
RewriteRule ^(.*)$ https://example.com/en/$1 [L]


References:

Comments

Popular posts from this blog

AVT Khyber TV Live Streaming

HTTP Live Streaming(HLS) With VAST by Using Fluid Player

WordPress Security(Part 07) by Sajid Javed