In one of our recent website app projects, we planned to use MongoDB as our main database. Since we are hardcore PHP guys, we do not even think of developing in some other language although we love Python a lot! In this article we will tell you in a step by step manner, how to set up Apache, MongoDB, PHP and Mongo-Php connects on a brand new Ubuntu 64 Bit Server.
Mongo DB homepage suggests using a 64 Bit server for installation but even if you have a 32 Bit server, Mongo DB would work just fine and fast. Its just that your DB would have to suffer an upper size limit of 2.5 GB if you are on a 32 Bit server. Lets begin the tutorial now:
Install the Apache server using this command:
sudo apt-get install apache2
After this your box will have the Apache web server up and running. Now, lets install MongoDB.
MongoDB packages are not available by default in the Ubuntu Software repositories as of now. So, we will have to add a new source to the server's default repository in order to get MongoDB. We hope MongoDB is soon added to the default Ubuntu software repo just like MySQL. Execute the following commands one by one:
sudo echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >> /etc/apt/sources.listsudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo apt-get update
Now Install the MongoDB package:
sudo apt-get install mongodb-10gen
After MongoDB is installed, we need to install the PHP component of our LAMP setup and then followed by the installation of the PHP-MongoDB connector. Lets do all that one by one.
This one is simple and many of you must have done it like a gazillion times already. Just use this command to get the essential PHP libraries along with PHP installation:
sudo apt-get install php5 php5-dev libapache2-mod-php5 php5-curl php5-gd apache2-threaded-dev build-essential php-pear
After this is done, we need to proceed to the installation of PHP-MongoDB connect.
Install / Setup PHP-MongoDB Connect
This is required for PHP to interact with MongoDB so without saying, this is a must install! Do it using this command from a terminal:
sudo pecl install mongo
Now add the following MongoDB driver identifier to the end of your php.ini configuration file.
You can also do it directly from the command line using this command but be extremely careful when you use the command below:
echo "extension=mongo.so" >> /etc/php5/apache2/php.ini
We are now almost done, Captain! Just reboot your Apache server or reload the settings and you will have brand new LAMP Setup (Linux Apache MongoDB PHP). Happy coding.
If you are having issues with setting up MongoDB on your servers, then do get in touch with us our programming support team will be glad to assist. Write to: firstname.lastname@example.org