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.
- Widely use.
- AWS Lightsail gives native support to Bitnami LAMP.
- 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/.
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:
- https://www.cloudbooklet.com/how-to-setup-geoip-block-using-apache/
- https://thecustomizewindows.com/2017/06/installing-geoip-module-apache2-ubuntu-16-04/
- https://linuxconfig.org/redirect-or-block-traffic-based-on-geographical-location-apache-geoip-mod
- https://community.bitnami.com/t/bitnami-stacks-magento-2-4-2-geoip-module/95916/2
- https://stackoverflow.com/questions/28567094/how-to-block-users-based-on-country-using-htaccess-and-geoip
- https://serverfault.com/questions/899882/geoip-redirect-all-but-specific-countries
- https://linuxconfig.org/redirect-or-block-traffic-based-on-geographical-location-apache-geoip-mod
Comments
Post a Comment