Tuesday, 20 September 2016

Install Apache, PHP and Configure PHP Mongo Driver on Linux

Article demonstrates on how to install Apache and Php. Later on will configure PHP Mongo driver. This articles covers only PHP Mongo driver configuration Please refer the below mentioned link for installing MongoDB in Linux. 

How to install MongoDB on Linux system

So lets begin with Apache configuration.

Installing Apache

[root@pract1 ~]# yum install httpd
Loaded plugins: refresh-packagekit, security
Setting up Install Process
Resolving Dependencies
--> Running transaction check
.....
Total download size: 910 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): httpd-2.2.15-54.0.1.el6_8.x86_64.rpm        | 832 kB     00:00
(2/2): httpd-tools-2.2.15-54.0.1.el6_8.x86_64.rpm  |  78 kB     00:00
.....
Updated:
  httpd.x86_64 0:2.2.15-54.0.1.el6_8

Dependency Updated:
  httpd-tools.x86_64 0:2.2.15-54.0.1.el6_8
.....
Complete!

Installing PHP

[root@pract1 ~]# yum install php php-pear php-devel gcc
Loaded plugins: refresh-packagekit, security
mongodb                      |  951 B     00:00
ol6_UEK_latest               | 1.2 kB     00:00
ol6_latest                   | 1.4 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
.....
Total download size: 33 M
Is this ok [y/N]: y
Downloading Packages:
(1/17): cpp-4.4.7-17.el6.x86_64.rpm                 | 3.7 MB     00:03
(2/17): gcc-4.4.7-17.el6.x86_64.rpm                 |  10 MB     00:09
(3/17): gcc-c++-4.4.7-17.el6.x86_64.rpm             | 4.7 MB     00:04
(4/17): gcc-gfortran-4.4.7-17.el6.x86_64.rpm        | 4.7 MB     00:04
(5/17): libgcc-4.4.7-17.el6.i686.rpm                | 114 kB     00:00
(6/17): libgcc-4.4.7-17.el6.x86_64.rpm              | 103 kB     00:00
(7/17): libgfortran-4.4.7-17.el6.x86_64.rpm         | 267 kB     00:00
(8/17): libgomp-4.4.7-17.el6.x86_64.rpm             | 134 kB     00:00
(9/17): libstdc++-4.4.7-17.el6.x86_64.rpm           | 295 kB     00:00
(10/17): libstdc++-devel-4.4.7-17.el6.x86_64.rpm    | 1.6 MB     00:01
(11/17): openssl-1.0.1e-48.el6_8.1.x86_64.rpm       | 1.5 MB     00:01
(12/17): openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm | 1.2 MB     00:01
(13/17): php-5.3.3-48.el6_8.x86_64.rpm              | 1.1 MB     00:01
(14/17): php-cli-5.3.3-48.el6_8.x86_64.rpm          | 2.2 MB     00:01
(15/17): php-common-5.3.3-48.el6_8.x86_64.rpm       | 529 kB     00:00
(16/17): php-devel-5.3.3-48.el6_8.x86_64.rpm        | 512 kB     00:01
(17/17): php-pear-1.9.4-5.el6.noarch.rpm            | 393 kB     00:00
.....
Total                                                                                                                                                                1.0 MB/s |  33 MB     00:33
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
......
Installed:
  php.x86_64 0:5.3.3-48.el6_8                                   php-devel.x86_64 0:5.3.3-48.el6_8                                   php-pear.noarch 1:1.9.4-5.el6

Dependency Installed:
  php-cli.x86_64 0:5.3.3-48.el6_8                                                                 php-common.x86_64 0:5.3.3-48.el6_8

Updated:
  gcc.x86_64 0:4.4.7-17.el6

Dependency Updated:
  cpp.x86_64 0:4.4.7-17.el6                   gcc-c++.x86_64 0:4.4.7-17.el6    gcc-gfortran.x86_64 0:4.4.7-17.el6    libgcc.i686 0:4.4.7-17.el6               libgcc.x86_64 0:4.4.7-17.el6
  libgfortran.x86_64 0:4.4.7-17.el6           libgomp.x86_64 0:4.4.7-17.el6    libstdc++.x86_64 0:4.4.7-17.el6       libstdc++-devel.x86_64 0:4.4.7-17.el6    openssl.x86_64 0:1.0.1e-48.el6_8.1
  openssl-devel.x86_64 0:1.0.1e-48.el6_8.1

Complete!

Configure PHP Mongo driver

[root@pract1 ~]# pecl install mongo
WARNING: "pecl/mongo" is deprecated in favor of "channel:///mongodb"
downloading mongo-1.6.14.tgz ...
Starting to download mongo-1.6.14.tgz (210,095 bytes)
.............................................done: 210,095 bytes
118 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
Build with Cyrus SASL (MongoDB Enterprise Authentication) support? [no] :
building in /var/tmp/pear-build-rootDwggHq/mongo-1.6.14
running: /var/tmp/mongo/configure --with-mongo-sasl=no
.....
Build complete.
Don't forget to run 'make test'.
......
running: make INSTALL_ROOT="/var/tmp/pear-build-rootDwggHq/install-mongo-1.6.14" install
Installing shared extensions:     /var/tmp/pear-build-rootDwggHq/install-mongo-1.6.14/usr/lib64/php/modules/
running: find "/var/tmp/pear-build-rootDwggHq/install-mongo-1.6.14" | xargs ls -dils
521531    4 drwxr-xr-x 3 root root    4096 Sep 19 21:33 /var/tmp/pear-build-rootDwggHq/install-mongo-1.6.14
.....
532128 1784 -rwxr-xr-x 1 root root 1824969 Sep 19 21:33 /var/tmp/pear-build-rootDwggHq/install-mongo-1.6.14/usr/lib64/php/modules/mongo.so

Build process completed successfully
Installing '/usr/lib64/php/modules/mongo.so'
install ok: channel://pecl.php.net/mongo-1.6.14
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
[root@pract1 ~]# 

Add MongoDB Extension and Verify

[root@pract1 ~]# vi /etc/php.ini
 Press i
 extension=mongo.so
 Press esc 
 :wq
[root@pract1 ~]#
Restart the apache services
[root@pract1 ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@pract1 ~]#

Now Verify if MongoDB drivers have been configured for PHP

[root@pract1 html]# php -m | grep -i mongo
mongo      --Output must be mongo which implies that PHP MongoDB driver have been configured successfully 
[root@pract1 html]# 

Another way to verify is to create one php file with below mentioned content 
[root@pract1 ~]# vi /var/www/html/phpinfo.php
 Press i
 <?php
 phpinfo();
 ?>
 Press esc 
 :wq

Open the web browser and check the phpinfo.php file using below mentioned address 
http://<ipaddress/hostname>/<port>/phpinfo.php
Ex:-     http://192.168.56.101/phpinfo.php
On web browser there has to be a mongo module similar to the one mentioned below


No comments:

Post a Comment