In this howto tutorial we will explore towards the setup of MongoDB on FreeBSD Operating system. MongoDB is a high-performance and scalable open source database application preferably designed for handling document-oriented storage with high availability. Moreover MongoDB is an ease of use to install, configure and maintain as compared to other database servers. It’s a server process that supports cross platforms and runs efficiently on Linux, Windows and OS X. We are going to setup its installation and configuration on FreeBSD 10.1 which is a UNIX like Operating System used for variety of platform because of its main features that is speed and its stability.
Before starting with the installation of MongoDB, make sure that you have considerable privileges on server to perform each step. there are different ways to install MongoDB on freeBSD and other distributions but in this tutorial we will go with two different methods to install MondoDB on freeBSD.
Login to root user and exceute the following commands to update your FreeBSD.
Installing MongoDB with PKG on FreeBSD
This is the simplest and easy way to install mongodb with package management tool on FreeBSD as it already provide us its package libraries and default configurations. Now start with the following steps to install mongodb.
STEP 1: Update PKG Repository
In order to update FreeBSD binary packages repository use the following command.
[email protected]:~ # pkg update –f
STEP 2: Install MongoDB
Run the PKG command to install the package from the updated FreeBSD repository catalog as.
[email protected]:~ # pkg install mongodb
This will install mongodb with addition of following new mandatory packages. Press "Y" to proceed.
New packages to be INSTALLED:
The process will require 268 MiB more space.
Proceed with this action? [y/N]: y
STEP 3: Enable Boot Startup
Once the packages are installed, configure rc.conf file to enable mongodb service start up at boot as.
[email protected]:~ # vi /etc/rc.conf
STEP 4: Start MongoDB Service
Now start the mongod service and confirms its active status.
STEP 5: Start Using Mongo Shell
MongoDB is ready to use on the shell, we can connect to the databases using mongo shell as.
[email protected]:~ # mongo
MongoDB shell version: 2.6.7
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
Questions? Try the support group
Installing MongoDB from Ports on FreeBSD
Installation of MongoDB from ports way is also a simple method but its a long process and mainly depends on connection speed. During its installation process it might ask about different dependent packages that we can choose and configure as per required.
STEP 1: Starting Installation
Our first step would be to change the directory to ports databases into monogodb and run the make install command.
[email protected]:~ # cd /usr/ports/databases/mongodb/
[email protected]:/usr/ports/databases/mongodb # ls
Makefile distinfo files pkg-descr pkg-plist
[email protected]:/usr/ports/databases/mongodb # make install clean
It will open a command prompt to choose from the option and press OK to proceed.
Similarly the installation process prompts for other packages to be configured as default or we can make changes to it like here it shows about the configuration settings of Python.
STEP 2: Configure Start-up Settings
Once the installation process completes we will configure its start up settings with its db and configurations path into rc.conf file.
[email protected]:/usr/ports/databases/mongodb # vi /etc/rc.conf
STEP 3: Configure MongoDB Conf
We can configure monogodb configurations file according to our environment as a single server node we will configure it to master with no http interface.
[email protected]:/usr/ports/databases/mongodb # vi /usr/local/etc/mongodb.conf
master = true
nohttpinterface = true
Now restart mongod service and start using mongo.
[email protected]:/usr/ports/databases/mongodb # service mongod start
Using MongoDB Shell
We can perform almost every function from the mongo shell.Let's take a review by using few simple commands on mongo shell.
To check all databases on the server run the follwoing command in mongo shell.
> show dbs
Now we create a simple test collection and insert some variables in it and then save that variables to the test database. We will use .save() command for saving the data into the new collection as shown.
Installing MongoDB PHP Interface
If you want to use mongoDB with php, then we can install pecl mongo extension for the administration of mongodb over the web. There are many other php extensions are available that we can install and use for mongo web interface. So, lets start with installing pecl-mongo installation on freeBSD from its ports.
Move to the ports directory for pecl-mongo and run make install command.
During the installation process it prompts for the options to choose as per required configurations of php, perl and libxml libraries. We can configure it with appropriate options.
Before the installation completes, pecl-mongo extension indiacated the default configurations of php that we can change through if required.
Now we access the web interface of pecl-mongo with port 27017 on localhost as below.
We learned to install mongodb on FreeBSD with PKG and Ports method with its basic configurations and using it on mongo shell and to access it over the web. I hope you get good idea with Mongo to build your own MongoDB environment on FreeBSD.