MaxMind GeoIP2 на ubuntu 16.04 + php5.6
Это просто маленькая шпаргалка на тему как поставить geoip2 на php5.6, только команды, без объяснений.
Исходный код библиотеки для PHP : https://github.com/maxmind/MaxMind-DB-Reader-php
aptitude purge geoip-database geoip-bin add-apt-repository ppa:maxmind/ppa apt-get update apt-get install geoipupdate ls -l /usr/share/GeoIP aptitude install libmaxminddb0 libmaxminddb-dev aptitude install php5.6-dev cd /usr/local/src git clone https://github.com/maxmind/MaxMind-DB-Reader-php.git cd ./MaxMind-DB-Reader-php/ext/ phpize ./configure make sudo make install echo "extension=maxminddb.so" > /etc/php/5.6/mods-available/maxminddb.ini ln -s /etc/php/5.6/mods-available/maxminddb.ini /etc/php/5.6/fpm/conf.d/@20-maxminddb.ini ln -s /etc/php/5.6/mods-available/maxminddb.ini /etc/php/5.6/cli/conf.d/@20-maxminddb.ini systemctl restart php5.6-fpm
Проверка (maxmindreader.php
):
<?php use MaxMind\Db\Reader; //$ipAddress = $_SERVER['REMOTE_ADDR']; $ipAddress = '24.24.24.24'; print_r($ipAddress); $databaseFile = '/usr/share/GeoIP/GeoLite2-City.mmdb'; $reader = new Reader($databaseFile); print_r($reader->get($ipAddress)); $reader->close();
Скрипт обновления базы (результат пишет в syslog, а значит можно прикрутить мониторинг):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #!/bin/bash # # Created by vps 23.09.2018 # # This script updates maxmind geoip database # == constants LOG_FACILITY='local2' LOG_LEVEL='notice' LOG_LEVEL_ERR='error' LOG_TAG="$0" # == end of constants say() { MESSAGE="$1" TIMESTAMP=$(date +"%F %T") echo -e "$TIMESTAMP $MESSAGE" logger -t $LOG_TAG -p $LOG_FACILITY.$LOG_LEVEL "$MESSAGE" } err() { MESSAGE="ERROR: $1" TIMESTAMP=$(date +"%F %T") echo -e $TIMESTAMP $MESSAGE >&2 logger -t $LOG_TAG -p $LOG_FACILITY.$LOG_LEVEL_ERR "$MESSAGE" set_wsrep_desync_off exit 1 } quit() { MESSAGE="$1" TIMESTAMP=$(date +"%F %T") echo -e $TIMESTAMP $MESSAGE >&2 logger -t $LOG_TAG -p $LOG_FACILITY.$LOG_LEVEL_ERR "$MESSAGE" set_wsrep_desync_off exit 0 } # == end of functions # == main program # cath control-c trap 'quit "Exit by SIGINT"' INT say "!!! Staring $0" OUT=`/usr/bin/geoipupdate 2>&1` || err "Unable update geoipdatabase: $OUT" say "!!! Done $0" |