How to install php-mongo on CentOS 5.3?
Asked Answered
M

5

6

I've already installed mongoDB on my VPS. It works well.

Now I want to install php driver to make php work with mongoDB.

I followed Mongo Installation but cannot find information I need. This manual contains only this notice:

If you are using CentOS or Redhat, Csoke Arpad created » RPMs for these distributions (PHP Mongo).

I'm not familiar with ssh commands on CentOS and distributions (what is it?). Can anyone help me install this php extension? Please provide all ssh commands needed to install it.

Thank you.

Mongolian answered 27/11, 2010 at 15:28 Comment(1)
You have not selected answer ... was this question answered? If you require more information please let us know. Thanks!Brazier
P
8

Try Justin's solution first with pecl (you'll want to use yum rather than aptitude to install php-devel), but if that doesn't work, I happen to have the manual build procedures on hand already for my own deploy reference. :)

Installing the PHP MongoDB driver

As root:

  1. export PHP_AUTOCONF=/usr/bin/autoconf
  2. export PHP_AUTOHEADER=/usr/bin/autoheader
  3. wget http://pecl.php.net/get/mongo-1.0.9.tgz
  4. tar -xzf mongo-1.0.9.tgz
  5. cd mongo-1.0.9
  6. phpize
  7. ./configure
  8. make && make install
  9. To /etc/php.d/mongo.ini, add: extension=mongo.so
Perception answered 28/11, 2010 at 22:31 Comment(3)
Command "pecl" not found on my VPS. So I apply your procedures and it rocks! One more question: how to keep mongod alive when I close PuTTy. I try "chkconfig --levels 235 mongod on, service mongod start" and "nohup mongod" but none of them work?Mongolian
You need to fork the process ... From the docs: This will fork the Mongo server and redirect its output to a logfile. As with --dbpath, you must create the log path yourself, Mongo will not create parent directories for you. $ ./mongod --fork --logpath /var/log/mongodb.log --logappendBrazier
Thank a lot Chris and Justin, you both really saved my days!Mongolian
B
12

If you have SSH access and root you should be able to follow the "Installing on *NIX" instructions (the RPMs are just created for convenience sake.)

You can try using pecl ... PECL is a repository for PHP Extensions and the mongo php driver uses that system.

Here is a blog post you might find helpful ...

http://learnmongo.com/posts/mongodb-php-install-and-connect/

Install instructions from that post ...

Command Line Install for Linux

Via your command line run pecl ... (if you use sudo):

$ sudo pecl install mongo

If you are already root ...

# pecl install mongo

If you get an error saying the system can’t find phpize then you may need to install the PHP dev package (this is how you do if your OS has aptitude, you might need to use some other method to install the PHP dev packaes) …

$ sudo aptitude install php5-dev

You will then need to edit your php.ini file add add the mongo.so extension:

extension=mongo.so

Restart your webserver and you are done.


If pecl doesn't work for you, you can manually install it as described here ...

http://www.php.net/manual/en/mongo.installation.php#mongo.installation.manual

Brazier answered 28/11, 2010 at 3:6 Comment(2)
Root prompts use # instead of $. Just saying.Florencio
On Redhat Enterprise 6.5 use yum install php54w-devel (PHP 5.4) or just yum install php-devel (PHP 5.3) if you hit the phpize issue.Vampire
E
10

I just installed it on centos using:

yum install php-pecl-mongo

Don't forget to restart the server to start using it: service httpd restart

Evangelist answered 12/7, 2013 at 5:39 Comment(0)
P
8

Try Justin's solution first with pecl (you'll want to use yum rather than aptitude to install php-devel), but if that doesn't work, I happen to have the manual build procedures on hand already for my own deploy reference. :)

Installing the PHP MongoDB driver

As root:

  1. export PHP_AUTOCONF=/usr/bin/autoconf
  2. export PHP_AUTOHEADER=/usr/bin/autoheader
  3. wget http://pecl.php.net/get/mongo-1.0.9.tgz
  4. tar -xzf mongo-1.0.9.tgz
  5. cd mongo-1.0.9
  6. phpize
  7. ./configure
  8. make && make install
  9. To /etc/php.d/mongo.ini, add: extension=mongo.so
Perception answered 28/11, 2010 at 22:31 Comment(3)
Command "pecl" not found on my VPS. So I apply your procedures and it rocks! One more question: how to keep mongod alive when I close PuTTy. I try "chkconfig --levels 235 mongod on, service mongod start" and "nohup mongod" but none of them work?Mongolian
You need to fork the process ... From the docs: This will fork the Mongo server and redirect its output to a logfile. As with --dbpath, you must create the log path yourself, Mongo will not create parent directories for you. $ ./mongod --fork --logpath /var/log/mongodb.log --logappendBrazier
Thank a lot Chris and Justin, you both really saved my days!Mongolian
E
4

I installed following the http://commandperls.com/install-mongodb-php-extension/

git clone git://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver
phpize
./configure
make
make install

then add a new line in php.ini

extension=mongo.so

Edythedythe answered 30/12, 2010 at 9:16 Comment(0)
M
0

This worked for CeontOS 7 and PHP 7.0.0. Similar to other answers but with some dependencies and submodel update command.

yum install cyrus-sasl cyrus-sasl-dev
cd /usr/src/
git clone git://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver
git submodule update --init
phpize
./configure
make
make install

Add extension to /usr/local/lib/php.ini

extension=mongodb.so

Restart PHP-FPM service

service php-fpm restart
Messiah answered 31/12, 2015 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.