cat /etc/redhat-release
===
CentOS Linux release 7.9.2009 (Core)
===
apachectl -v
===
Server version: Apache/2.4.6 (CentOS)
Server built: May 30 2023 14:01:11
===
php -v
===
PHP 7.0.33 (cli) (built: Aug 2 2023 10:48:43) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with the ionCube PHP Loader + ionCube24 v13.0.2, Copyright (c) 2002-2023, by ionCube Ltd.
with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies
===
yum install -y epel-release
yum install php-pecl-geoip
# 버전 확인 후 [y]
======================================================================================================================
Package Arch Version Repository Size
======================================================================================================================
Installing:
php-pecl-geoip x86_64 1.1.1-1.el7.remi.7.0 remi-php70 23 k
Transaction Summary
======================================================================================================================
Install 1 Package
php -m | grep geoip
===
geoip
===
yum install -y GeoIP GeoIP-data
간단한 접속자의 IP로 국가조회하는 소스입니다.
vi geoip.php
<?php // Check if the GeoIP extension is loaded if (!extension_loaded('geoip')) { die('GeoIP extension is not loaded.'); } // Get the visitor's IP address $ip = $_SERVER['REMOTE_ADDR']; // Get the location information for the IP address $country = geoip_country_name_by_name($ip); $country_code = geoip_country_code_by_name($ip); // Display the results echo "IP Address: $ip<br>"; echo "Country: $country<br>"; echo "Country Code: $country_code<br>"; ?>
yum install -y geoipupdate
vi /etc/GeoIP.conf
AccountID 0 LicenseKey 000000000000 EditionIDs GeoLite2-Country GeoLite2-City
위 세 줄을 수정하면 됩니다.
0 3 * * 1 logger "GeoIP Update" && /bin/geoipupdate
매주 월요일 오전 03시 진행 하도록 설정하고 시스템 로그(message)에 기록을 남기도록 기재했습니다.