• Home
  • Technology
    • Ebullientech
    • Entrepreneurship
    • Video Technology
    • Cloud Computing
    • Business Analysis
  • Healthcare
    • Pharmacology
  • Thoughts
    • Food
    • General
    • Stories
    • Places
    • Workplace
    • Social Issues
    • Reviews
  • Quotes
  • Ebullientech News and Events
  • About

Kamalika's Notebook

thinking nothing...............!!

You are here: Home / Kamalika / Technology / mongoDB / Installing mongoDB in CentOS and Connecting to mongoDB from PHP

Installing mongoDB in CentOS and Connecting to mongoDB from PHP

May 24, 2013 By Kamalika Leave a Comment

Part 2: Installing PHP mongo extension and make it work!

Before we install PHP mongo extension, we need to install a few development packages otherwise we might get errors like:

phpize: command not found
configure: error no acceptable c compiler found in $path

So the package(s) we’ll have to install is:

[bash]yum groupinstall “Development Tools”[/bash]

The above will install about 75 new development packages!

Next would be to install PHP mongo extension:

[bash]pecl install mongo[/bash]

Next add mongo.so to php.ini as a PHP extension:

[bash]vi /etc/php.ini[/bash]

Add the following lines and to a Apache restart:

[bash][mongo]
extension=mongo.so[/bash]

Now you have to test whether PHP mongo extension is working:

[bash]vi info.php[/bash]

Add the following lines of code:

[php]<?php

ini_set(‘display_errors’, ‘1’);
$m = new Mongo();
print_r($m);
?>[/php]

Remember to keep display_errors ‘On’ is absolutely critical here because PHP mongo extension is working but by default in certain setups (read most setups!), Apache doesn’t allow requests to make network connections which in turns throws the following error:

Fatal error: Uncaught exception ‘MongoConnectionException’ with message ‘Failed to connect to: localhost:27017: Unknown error’.

You’ll need to fix this by running the following command:

[bash]/usr/sbin/setsebool -P httpd_can_network_connect 1[/bash]

Don’t worry this command takes about 1/2 a minute to execute, but it works!

Below is what you get as output:

Mongo Object
(
    [connected] => 1
    [status] =>
    [server:protected] =>
    [persistent:protected] =>
)

Now mongoDB as well as a mongo cache system is ready to use.

DISCLAIMER: I have written the exact steps I followed and issues I faced while trying to install and configure mongoDB and PHP mongo extension on CentOS 6.3, this should mostly work in general but I hold no guarantee that it would definitely work! It was sheer joy which drove me to write this article after I saw the output without errors. I thought of sharing the experience with my fellow Open Source Developers across the Globe!

 

Pages: 1 2

Filed Under: mongoDB, Technology Tagged With: Installing mongoDB, mongoDB, PHP mongo Extension

« Installing LAMP in Centos 6.3
Reading J. K. Rowling Books »

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

Let’s connect…

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube

Hello There…

I'm Kamalika, a techpreneur & startup mentor, blogger, hobbyist photographer, Netflix & Kindle indulgent, food connoisseur, Starbucks aficionado and former Disney employee ...next

Looking for something?

Tags

All in One SEO Pack AWS Banaras Blogger Blogging Blogs Dasaswamedh Ghat Ebullientech Ebullientech Interactive LLP Facebook Facebook Developers father's day father's day wishes father's day wishes for dad fathers day love Fathers Day Special Fathers Day wishes from daughter Father’s day memories GeoTech GeoTech Informatics HipHop for PHP Kamalika Guha Roy Kashi Ganga LAMP MySQL Nabaneeta Guha Roy Online Marketing PayPal PayPal's suspension of Indian bank transactions PHP PHP & MySQL Saraswati Puja Search Engine Optimization SEO Startup The Ganges TypePad UCO HUT Varanasi Web 2.0 Web 2.0 Design Web Design Web Marketing WordPress WordPress.COM

Timeline

  • 2024 (1)
  • 2021 (3)
  • 2020 (7)
  • 2019 (4)
  • 2018 (1)
  • 2015 (6)
  • 2014 (13)
  • 2013 (9)
  • 2010 (7)
  • 2009 (2)

Topics

Copyright © 2021 · Kamalika Guha Roy, Powered by: Ebullientech