Monthly Archives: October 2013

Install MongoDB in Ubuntu 12.04 with PHP driver

Install MongoDB:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-10gen

Install MongoDB PHP driver:

sudo apt-get install php-pear php5-dev
sudo pecl search mongo
sudo pecl install mongo

Configure MongoDB PHP driver: Create a file called /etc/php5/mods-available/mongo.ini with this content:

extension=mongo.so

And create a symlink to it in /etc/php5/conf.d/:

cd /etc/php5/conf.d
sudo ln -s ../mods-available/mongo.ini 20-mongo.ini

If the folder mods-available does not exists, create the mongo.ini file in /etc/php5/conf.d/.

Then restart Apache:

sudo service apache2 restart

Start, stop and restart MongoDB:

sudo service mongodb start
sudo service mongodb stop
sudo service mongodb restart

Configuration file:

/etc/mongodb.conf

Log file:

/var/log/mongodb/mongodb.log

Data files:

/var/lib/mongodb

Ref: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

Select different available java and javac versions in Ubuntu with update-alternatives

It’s possible to have more than one version of Java in the same machine.

If you have more than one Java JRE or JDK installed you can switch between them with the update-alternatives command:

$ sudo /usr/sbin/update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java to provide /usr/bin/java (java) in manual mode.

You can do just the same for javac:

$ sudo /usr/sbin/update-alternatives --config javac

There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                        Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-i386/bin/javac   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/bin/javac   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-i386/bin/javac   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-openjdk-i386/bin/javac to provide /usr/bin/javac (javac) in manual mode.

You can check wich version is currently in use running:

$ java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK Server VM (build 23.7-b01, mixed mode)
$ javac -version
javac 1.7.0_25