PHP: how to installing GeoIP extension on CentOS


Read more:
How to install GeoIp module for PHP on Windows

PHP5

Step 1: check your PHP version

yum list installed |grep php

Result:

kloxo-core-php.i386               5.3.28-2                             installed
php54w.i386                       5.4.45-2.w5                          installed
php54w-cli.i386                   5.4.45-2.w5                          installed
php54w-common.i386                5.4.45-2.w5                          installed
php54w-devel.i386                 5.4.45-2.w5                          installed
php54w-gd.i386                    5.4.45-2.w5                          installed
php54w-imap.i386                  5.4.45-2.w5                          installed
php54w-mbstring.i386              5.4.45-2.w5                          installed
php54w-mcrypt.i386                5.4.45-2.w5                          installed
php54w-mysql.i386                 5.4.45-2.w5                          installed
php54w-pdo.i386                   5.4.45-2.w5                          installed
php54w-pear.noarch                1:1.10.1-1.w5                        installed
php54w-process.i386               5.4.45-2.w5                          installed
php54w-xml.i386                   5.4.45-2.w5                          installed

So, in this example, we use PHP5.4

check php version

Step 2:

mkdir /usr/share/GeoIP && cd /usr/share/GeoIP

Step 3:

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

Result:

[root@tutorialspots GeoIP]# wget http://geolite.maxmind.com/download/geoip/database/G
eoLiteCountry/GeoIP.dat.gz
--2016-09-14 04:45:07--  http://geolite.maxmind.com/download/geoip/database/GeoL
iteCountry/GeoIP.dat.gz
Resolving geolite.maxmind.com... 104.16.37.47, 104.16.38.47, 2400:cb00:2048:1::6
810:262f, ...
Connecting to geolite.maxmind.com|104.16.37.47|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 596612 (583K) [application/octet-stream]
Saving to: `GeoIP.dat.gz'

100%[======================================>] 596,612     --.-K/s   in 0.04s

2016-09-14 04:45:07 (13.6 MB/s) - `GeoIP.dat.gz' saved [596612/596612]

Step 4:

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Result:

[root@tutorialspots GeoIP]# wget http://geolite.maxmind.com/download/geoip/database/G
eoLiteCity.dat.gz
--2016-09-14 04:45:53--  http://geolite.maxmind.com/download/geoip/database/GeoL
iteCity.dat.gz
Resolving geolite.maxmind.com... 104.16.37.47, 104.16.38.47, 2400:cb00:2048:1::6
810:252f, ...
Connecting to geolite.maxmind.com|104.16.37.47|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13858391 (13M) [application/octet-stream]
Saving to: `GeoLiteCity.dat.gz'

100%[======================================>] 13,858,391  41.5M/s   in 0.3s

2016-09-14 04:45:55 (41.5 MB/s) - `GeoLiteCity.dat.gz' saved [13858391/13858391]

Step 5:

gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz

Then rename file GeoLiteCity.dat to GeoIPCity.dat

Step 6:

yum update

Result:

[root@tutorialspots GeoIP]# yum update
Loaded plugins: fastestmirror, protectbase, replace
Determining fastest mirrors
Could not retrieve mirrorlist http://apt.sw.be/redhat/el5/en/mirrors-rpmforge er
ror was
[Errno 14] HTTP Error 404: Not Found
 * addons: mirror.steadfast.net
 * base: mirror.cc.columbia.edu
 * extras: mirrors.centos.webair.com
 * rpmforge: repoforge.spinellicreations.com
 * updates: mirror.es.its.nyu.edu
 * webtatic-el5: us-east.repo.webtatic.com
addons                                                   | 1.9 kB     00:00
base                                                     | 1.1 kB     00:00
extras                                                   | 2.1 kB     00:00
flexbox                                                  | 1.9 kB     00:00
http://download.lxcenter.org/download/update/lxgeneral/repodata/repomd.xml: [Err
no 4] IOError: <urlopen error (-2, 'Name or service not known')>
Trying other mirror.
http://download.lxcenter.org/download/update/centos-5/i386/repodata/repomd.xml:
[Errno 4] IOError: <urlopen error (-2, 'Name or service not known')>
Trying other mirror.
rpmforge                                                 | 1.9 kB     00:00
updates                                                  | 1.9 kB     00:00
updates/primary_db                                       | 756 kB     00:00
vz-base                                                  |  951 B     00:00
vz-updates                                               |  951 B     00:00
webtatic-el5                                             | 2.5 kB     00:00
webtatic-el5/primary_db                                  |  66 kB     00:00
0 packages excluded due to repository protections
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package dhclient.i386 12:4.1.1-9.centos5 set to be updated
---> Package kernel-devel.i686 0:2.6.18-412.el5 set to be installed
---> Package kernel-headers.i386 0:2.6.18-412.el5 set to be updated
---> Package mhash.i386 0:0.9.9-1.el5.rf set to be updated
---> Package openssl.i686 0:0.9.8e-40.el5_11 set to be updated
---> Package openssl-devel.i386 0:0.9.8e-40.el5_11 set to be updated
---> Package perl-Archive-Tar.noarch 1:1.68-1 set to be updated
--> Processing Dependency: perl(Package::Constants) for package: perl-Archive-Ta
r
---> Package perl-Convert-ASN1.noarch 0:0.22-1.el5 set to be updated
---> Package perl-DBD-MySQL.i386 1:4.017-1 set to be updated
---> Package perl-DBI.i386 0:1.615-2 set to be updated
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI
---> Package perl-Digest-SHA1.i386 1:2.13-11 set to be updated
---> Package perl-IO-Socket-INET6.noarch 1:2.65-1 set to be updated
---> Package perl-NetAddr-IP.i386 1:4.033-1 set to be updated
---> Package perl-URI.noarch 1:1.56-1 set to be updated
---> Package perl-libwww-perl.noarch 0:5.834-1.el5 set to be updated
--> Processing Dependency: perl(IO::Uncompress::Inflate) for package: perl-libww
w-perl
--> Processing Dependency: perl(IO::Uncompress::Gunzip) for package: perl-libwww
-perl
--> Processing Dependency: perl(Compress::Raw::Zlib) for package: perl-libwww-pe
rl
--> Processing Dependency: perl(Crypt::SSLeay) for package: perl-libwww-perl
--> Processing Dependency: perl(IO::Uncompress::RawInflate) for package: perl-li
bwww-perl
--> Processing Dependency: perl(IO::Compress::Gzip) for package: perl-libwww-per
l
--> Processing Dependency: perl(IO::Compress::Deflate) for package: perl-libwww-
perl
---> Package perl-rrdtool.i386 0:1.4.7-1.el5.rf set to be updated
---> Package rpmforge-release.i386 0:0.5.3-1.el5.rf set to be updated
---> Package rrdtool.i386 0:1.4.7-1.el5.rf set to be updated
--> Processing Dependency: libdbi.so.0 for package: rrdtool
---> Package rsync.i386 0:3.0.7-1.el5 set to be updated
---> Package rsyslog.i386 0:4.4.2-2.centos5 set to be updated
---> Package t1lib.i386 0:5.1.2-1.el5.rf set to be updated
---> Package tzdata.i386 0:2016f-1.el5 set to be updated
---> Package webalizer.i386 0:2.21_02-3.3.el5 set to be updated
--> Running transaction check
---> Package libdbi.i386 0:0.8.1-2.1 set to be updated
---> Package perl-Compress-Raw-Zlib.i386 1:2.030-1 set to be updated
---> Package perl-Crypt-SSLeay.i386 0:0.51-11.el5 set to be updated
---> Package perl-IO-Compress.noarch 1:2.030-1 set to be updated
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.030 for package: perl
-IO-Compress
---> Package perl-Package-Constants.noarch 0:0.02-1.el5.rf set to be updated
---> Package perl-PlRPC.noarch 0:0.2020-1.rf set to be updated
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC
--> Processing Dependency: perl(Net::Daemon) for package: perl-PlRPC
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.i386 1:2.031-1 set to be updated
---> Package perl-Net-Daemon.noarch 0:0.43-8 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                    Arch      Version                 Repository   Size
================================================================================
Installing:
 dhclient                   i386      12:4.1.1-9.centos5      flexbox     348 k
     replacing  dhcpv6-client.i386 1.0.10-22.el5_11

 kernel-devel               i686      2.6.18-412.el5          updates     5.9 M
 mhash                      i386      0.9.9-1.el5.rf          rpmforge    201 k
     replacing  libmhash.i386 0.9.1-1.2.el5.rf

 rsyslog                    i386      4.4.2-2.centos5         flexbox     414 k
     replacing  sysklogd.i386 1.4.1-46.el5

Updating:
 kernel-headers             i386      2.6.18-412.el5          updates     1.5 M
 openssl                    i686      0.9.8e-40.el5_11        updates     1.7 M
 openssl-devel              i386      0.9.8e-40.el5_11        updates     1.9 M
 perl-Archive-Tar           noarch    1:1.68-1                flexbox      64 k
 perl-Convert-ASN1          noarch    0.22-1.el5              flexbox      39 k
 perl-DBD-MySQL             i386      1:4.017-1               flexbox     137 k
 perl-DBI                   i386      1.615-2                 flexbox     865 k
 perl-Digest-SHA1           i386      1:2.13-11               flexbox      26 k
 perl-IO-Socket-INET6       noarch    1:2.65-1                flexbox      16 k
 perl-NetAddr-IP            i386      1:4.033-1               flexbox      95 k
 perl-URI                   noarch    1:1.56-1                flexbox      99 k
 perl-libwww-perl           noarch    5.834-1.el5             flexbox     390 k
 perl-rrdtool               i386      1.4.7-1.el5.rf          rpmforge     52 k
 rpmforge-release           i386      0.5.3-1.el5.rf          rpmforge     12 k
 rrdtool                    i386      1.4.7-1.el5.rf          rpmforge    906 k
 rsync                      i386      3.0.7-1.el5             flexbox     342 k
 t1lib                      i386      5.1.2-1.el5.rf          rpmforge    362 k
 tzdata                     i386      2016f-1.el5             updates     775 k
 webalizer                  i386      2.21_02-3.3.el5         flexbox     137 k
Installing for dependencies:
 libdbi                     i386      0.8.1-2.1               base         35 k
 perl-Compress-Raw-Bzip2    i386      1:2.031-1               flexbox      54 k
 perl-Compress-Raw-Zlib     i386      1:2.030-1               flexbox      99 k
 perl-Crypt-SSLeay          i386      0.51-11.el5             base         45 k
 perl-IO-Compress           noarch    1:2.030-1               flexbox     240 k
 perl-Net-Daemon            noarch    0.43-8                  flexbox      37 k
 perl-Package-Constants     noarch    0.02-1.el5.rf           rpmforge    7.8 k
 perl-PlRPC                 noarch    0.2020-1.rf             flexbox      34 k

Transaction Summary
================================================================================
Install      12 Package(s)
Upgrade      19 Package(s)

Total size: 17 M
Total download size: 13 M
Is this ok [y/N]: y
Downloading Packages:
(1/13): perl-Package-Constants-0.02-1.el5.rf.noarch.rpm  | 7.8 kB     00:00
(2/13): rpmforge-release-0.5.3-1.el5.rf.i386.rpm         |  12 kB     00:00
(3/13): libdbi-0.8.1-2.1.i386.rpm                        |  35 kB     00:00
(4/13): perl-Net-Daemon-0.43-8.noarch.rpm                |  37 kB     00:00
(5/13): perl-rrdtool-1.4.7-1.el5.rf.i386.rpm             |  52 kB     00:00
(6/13): mhash-0.9.9-1.el5.rf.i386.rpm                    | 201 kB     00:00
(7/13): t1lib-5.1.2-1.el5.rf.i386.rpm                    | 362 kB     00:00
(8/13): tzdata-2016f-1.el5.i386.rpm                      | 775 kB     00:00
(9/13): rrdtool-1.4.7-1.el5.rf.i386.rpm                  | 906 kB     00:00
(10/13): kernel-headers-2.6.18-412.el5.i386.rpm          | 1.5 MB     00:00
(11/13): openssl-0.9.8e-40.el5_11.i686.rpm               | 1.7 MB     00:00
(12/13): openssl-devel-0.9.8e-40.el5_11.i386.rpm         | 1.9 MB     00:00
(13/13): kernel-devel-2.6.18-412.el5.i686.rpm            | 5.9 MB     00:00
--------------------------------------------------------------------------------
Total                                           4.2 MB/s |  13 MB     00:03
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test


Transaction Check Error:
  file /usr/share/man/man3/Compress::Zlib.3pm.gz from install of perl-IO-Compres
s-2.030-1.noarch conflicts with file from package perl-Compress-Zlib-1.42-1.fc6.
i386

Error Summary
-------------

Step 7:

yum install geoip geoip-devel

If you don’t install packages php-devel and php-pear yet, you use this command:

yum install php54w-devel php54w-pear geoip geoip-devel

Result:

[root@tutorialspots GeoIP]# yum install geoip geoip-devel
Loaded plugins: fastestmirror, protectbase, replace
Loading mirror speeds from cached hostfile
 * addons: mirror.steadfast.net
 * base: mirror.cc.columbia.edu
 * extras: mirrors.centos.webair.com
 * rpmforge: repoforge.spinellicreations.com
 * updates: mirror.es.its.nyu.edu
 * webtatic-el5: us-east.repo.webtatic.com
http://download.lxcenter.org/download/update/lxgeneral/repodata/repomd.xml: [Err
no 4] IOError: <urlopen error (-2, 'Name or service not known')>
Trying other mirror.
http://download.lxcenter.org/download/update/centos-5/i386/repodata/repomd.xml:
[Errno 4] IOError: <urlopen error (-2, 'Name or service not known')>
Trying other mirror.
0 packages excluded due to repository protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package geoip.i386 0:1.4.6-1.el5.rf set to be updated
---> Package geoip-devel.i386 0:1.4.6-1.el5.rf set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch         Version                Repository        Size
================================================================================
Installing:
 geoip               i386         1.4.6-1.el5.rf         rpmforge         782 k
 geoip-devel         i386         1.4.6-1.el5.rf         rpmforge         7.3 k

Transaction Summary
================================================================================
Install       2 Package(s)
Upgrade       0 Package(s)

Total download size: 789 k
Is this ok [y/N]: y
Downloading Packages:
http://repoforge.spinellicreations.com/redhat/el5/en/i386/rpmforge/RPMS/geoip-de
vel-1.4.6-1.el5.rf.i386.rpm: [Errno 12] Timeout: <urlopen error timed out>
Trying other mirror.
(1/2): geoip-devel-1.4.6-1.el5.rf.i386.rpm               | 7.3 kB     00:00
(2/2): geoip-1.4.6-1.el5.rf.i386.rpm                     | 782 kB     00:00
--------------------------------------------------------------------------------
Total                                            26 kB/s | 789 kB     00:30
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : geoip                                                    1/2
  Installing     : geoip-devel                                              2/2

Installed:
  geoip.i386 0:1.4.6-1.el5.rf         geoip-devel.i386 0:1.4.6-1.el5.rf

Complete!

Step 8:

pecl channel-update pecl.php.net
pecl install geoip

Step 9:

echo "extension=geoip.so" > /etc/php.d/geoip.ini

Note: add more a line to the file /etc/php.d/geoip.ini

geoip.custom_directory = /usr/share/GeoIP/

Step 10: restart Apache service

service httpd restart

If unsuccessfully, you can change the step 8 to step 8.1:

wget http://pecl.php.net/get/geoip-1.1.1.tgz

Result:

[root@tutorialspots GeoIP]# wget http://pecl.php.net/get/geoip-1.1.1.tgz
--2016-09-14 05:27:45--  http://pecl.php.net/get/geoip-1.1.1.tgz
Resolving pecl.php.net... 104.236.228.160
Connecting to pecl.php.net|104.236.228.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13004 (13K) [application/octet-stream]
Saving to: `geoip-1.1.1.tgz'

100%[======================================>] 13,004      --.-K/s   in 0s

2016-09-14 05:27:45 (442 MB/s) - `geoip-1.1.1.tgz' saved [13004/13004]

Step 8.2

tar -zxvf geoip-1.1.1.tgz
cd geoip-1.1.1

Result:

[root@tutorialspots GeoIP]# tar -zxvf geoip-1.1.1.tgz
package.xml
geoip-1.1.1/tests/001.phpt
geoip-1.1.1/tests/002.phpt
geoip-1.1.1/tests/003.phpt
geoip-1.1.1/tests/004.phpt
geoip-1.1.1/tests/005.phpt
geoip-1.1.1/tests/006.phpt
geoip-1.1.1/tests/007.phpt
geoip-1.1.1/tests/008.phpt
geoip-1.1.1/tests/009.phpt
geoip-1.1.1/tests/010.phpt
geoip-1.1.1/tests/011.phpt
geoip-1.1.1/tests/013.phpt
geoip-1.1.1/tests/014.phpt
geoip-1.1.1/tests/015.phpt
geoip-1.1.1/tests/016.phpt
geoip-1.1.1/tests/017.phpt
geoip-1.1.1/tests/018.phpt
geoip-1.1.1/tests/019.phpt
geoip-1.1.1/ChangeLog
geoip-1.1.1/config.m4
geoip-1.1.1/config.w32
geoip-1.1.1/geoip.def
geoip-1.1.1/geoip.c
geoip-1.1.1/php_geoip.h
geoip-1.1.1/README
geoip-1.1.1/LICENSE

Step 8.3

phpize

Result:

[root@tutorialspots geoip-1.1.1]# phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525

Step 8.4:

./configure --with-php-config=/usr/local/bin/php-config

or

./configure --with-php-config=/usr/bin/php-config

Result:

[root@tutorialspots geoip-1.1.1]# ./configure --with-php-config=/usr/bin/php-config
checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ANSI C... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-redhat-linux-gnu
checking host system type... i686-redhat-linux-gnu
checking target system type... i686-redhat-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/i
nclude/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/ph
p/ext/date/lib
checking for PHP extension directory... /usr/lib/php/modules
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate
 PHP parsers.
checking for gawk... gawk
checking for geoip support... yes, shared
checking for geoip files in default path... found in /usr
checking for GeoIP_open in -lGeoIP... yes
checking for GeoIP_setup_custom_directory in -lGeoIP... yes
checking for GeoIP_set_charset in -lGeoIP... yes
checking for GeoIP_continent_by_id in -lGeoIP... yes
checking for GeoIP_addr_to_num in -lGeoIP... no
checking whether GEOIP_NETSPEED_EDITION_REV1 is declared... no
checking whether GEOIP_ACCURACYRADIUS_EDITION is declared... no
checking for LGPL compatible GeoIP libs... found 1004006
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognise dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for g77... no
checking for f77... no
checking for xlf... no
checking for frt... no
checking for pgf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for f90... no
checking for xlf90... no
checking for pgf90... no
checking for epcf90... no
checking for f95... f95
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether f95 accepts -g... yes
checking the maximum length of command line arguments... 32768
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating libtool
appending configuration tag "CXX" to libtool
appending configuration tag "F77" to libtool
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for f95 option to produce PIC... -fPIC
checking if f95 PIC flag -fPIC works... yes
checking if f95 static flag -static works... yes
checking if f95 supports -c -o file.o... yes
checking whether the f95 linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
configure: creating ./config.status
config.status: creating config.h

Step 8.5

make

Result:

[root@tutorialspots geoip-1.1.1]# make
/bin/sh /usr/share/GeoIP/geoip-1.1.1/libtool --mode=compile cc  -I. -I/usr/share
/GeoIP/geoip-1.1.1 -DPHP_ATOM_INC -I/usr/share/GeoIP/geoip-1.1.1/include -I/usr/
share/GeoIP/geoip-1.1.1/main -I/usr/share/GeoIP/geoip-1.1.1 -I/usr/include/php -
I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/in
clude/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr
/share/GeoIP/geoip-1.1.1/geoip.c -o geoip.lo
mkdir .libs
 cc -I. -I/usr/share/GeoIP/geoip-1.1.1 -DPHP_ATOM_INC -I/usr/share/GeoIP/geoip-1
.1.1/include -I/usr/share/GeoIP/geoip-1.1.1/main -I/usr/share/GeoIP/geoip-1.1.1
-I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/includ
e/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_
H -g -O2 -c /usr/share/GeoIP/geoip-1.1.1/geoip.c  -fPIC -DPIC -o .libs/geoip.o
In file included from /usr/share/GeoIP/geoip-1.1.1/php_geoip.h:56,
                 from /usr/share/GeoIP/geoip-1.1.1/geoip.c:35:
/usr/share/GeoIP/geoip-1.1.1/geoip.def:28:7: warning: no newline at end of file
In file included from /usr/share/GeoIP/geoip-1.1.1/geoip.c:48:
/usr/share/GeoIP/geoip-1.1.1/geoip.def:28:7: warning: no newline at end of file
In file included from /usr/share/GeoIP/geoip-1.1.1/geoip.c:444:
/usr/share/GeoIP/geoip-1.1.1/geoip.def: In function 'zif_geoip_country_code_by_n
ame_v6':
/usr/share/GeoIP/geoip-1.1.1/geoip.def:25: warning: assignment makes pointer fro
m integer without a cast
/usr/share/GeoIP/geoip-1.1.1/geoip.def: In function 'zif_geoip_country_code3_by_
name_v6':
/usr/share/GeoIP/geoip-1.1.1/geoip.def:26: warning: assignment makes pointer fro
m integer without a cast
/usr/share/GeoIP/geoip-1.1.1/geoip.def: In function 'zif_geoip_country_name_by_n
ame_v6':
/usr/share/GeoIP/geoip-1.1.1/geoip.def:27: warning: assignment makes pointer fro
m integer without a cast
In file included from /usr/share/GeoIP/geoip-1.1.1/geoip.c:444:
/usr/share/GeoIP/geoip-1.1.1/geoip.def:28:7: warning: no newline at end of file
/bin/sh /usr/share/GeoIP/geoip-1.1.1/libtool --mode=link cc -DPHP_ATOM_INC -I/us
r/share/GeoIP/geoip-1.1.1/include -I/usr/share/GeoIP/geoip-1.1.1/main -I/usr/sha
re/GeoIP/geoip-1.1.1 -I/usr/include/php -I/usr/include/php/main -I/usr/include/p
hp/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/da
te/lib  -DHAVE_CONFIG_H  -g -O2   -o geoip.la -export-dynamic -avoid-version -pr
efer-pic -module -rpath /usr/share/GeoIP/geoip-1.1.1/modules  geoip.lo -lGeoIP
cc -shared  .libs/geoip.o  -lGeoIP  -Wl,-soname -Wl,geoip.so -o .libs/geoip.so
creating geoip.la
(cd .libs && rm -f geoip.la && ln -s ../geoip.la geoip.la)
/bin/sh /usr/share/GeoIP/geoip-1.1.1/libtool --mode=install cp ./geoip.la /usr/s
hare/GeoIP/geoip-1.1.1/modules
cp ./.libs/geoip.so /usr/share/GeoIP/geoip-1.1.1/modules/geoip.so
cp ./.libs/geoip.lai /usr/share/GeoIP/geoip-1.1.1/modules/geoip.la
PATH="$PATH:/sbin" ldconfig -n /usr/share/GeoIP/geoip-1.1.1/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/share/GeoIP/geoip-1.1.1/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Step 8.6:

make install

Result:

[root@tutorialspots geoip-1.1.1]# make install
Installing shared extensions:     /usr/lib/php/modules/

To check if GeoIp install successfully

php -m

If you get the error

geoip.so: undefined symbol: GeoIP_country_code_ by_name_v6 in Unknown on line 0

You must use GeoIp 1.0.8 instead by v1.1.1.

Note 1: to use function geoip_org_by_name you must have the file GeoIPOrg.dat, you can download it here:
https://github.com/nateweiss/geoip-data-files/blob/master/GeoIPOrg.dat?raw=true

Note 2: file: GeoIPv6.dat
https://github.com/nccgroup/typofinder/blob/master/TypoMagic/datasources/GeoIPv6.dat?raw=true
or
https://osdn.net/projects/sfnet_slackbuildsdirectlinks/downloads/GeoIP/GeoIPv6.dat.gz/

PHP7

Step 1: yum install -y php71-php-pecl-geoip

[root@tutorialspots ~]# yum install -y php71-php-pecl-geoip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.sesp.northwestern.edu
 * epel: fedora-epel.mirror.lstn.net
 * extras: mirror.trouble-free.net
 * ius: dfw.mirror.rackspace.com
 * nux-dextop: mirror.li.nux.ro
 * remi-safe: repo1.dal.innoscale.net
 * updates: repo1.dal.innoscale.net
Resolving Dependencies
--> Running transaction check
---> Package php71-php-pecl-geoip.x86_64 0:1.1.1-3.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch       Version                Repository     Size
================================================================================
Installing:
 php71-php-pecl-geoip     x86_64     1.1.1-3.el7.remi       remi-safe      20 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 20 k
Installed size: 40 k
Downloading packages:
php71-php-pecl-geoip-1.1.1-3.el7.remi.x86_64.rpm           |  20 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php71-php-pecl-geoip-1.1.1-3.el7.remi.x86_64                 1/1
  Verifying  : php71-php-pecl-geoip-1.1.1-3.el7.remi.x86_64                 1/1

Installed:
  php71-php-pecl-geoip.x86_64 0:1.1.1-3.el7.remi

Complete!

Step 2: Find geoip.so and geoip.ini

[root@tutorialspots ~]# find / -name geoip.so
/opt/remi/php71/root/usr/lib64/php/modules/geoip.so
[root@tutorialspots ~]# find / -name *geoip.ini
/etc/opt/remi/php71/php.d/40-geoip.ini

Step 3: create symbolic links

ln -s /etc/opt/remi/php71/php.d/40-geoip.ini /etc/php.d/40-geoip.ini
ln -s /opt/remi/php71/root/usr/lib64/php/modules/geoip.so /usr/lib64/php/modules/geoip.so 

Step 4: restart PHP-FPM

service php-fpm restart

Leave a Reply