DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. Getting Started with Drupal and MongoDB

Getting Started with Drupal and MongoDB

rouletteroulette rouletteroulette user avatar by
rouletteroulette rouletteroulette
·
Apr. 02, 12 · Interview
Like (0)
Save
Tweet
Share
15.68K Views

Join the DZone community and get the full member experience.

Join For Free

MongoDB is the most full featured scalable database taking the tech world by storm. Drupal is the standard in content management powering magazines, blogs online newspapers and much more. It’s only natural that they would get together to provide a fast dynamic scalable CMS system. Whenever a Drupal site needs to scale dynamic content they turn to MongoDB to be able to deliver. The Examiner.com was the pioneer in this approach and many Drupal sites have followed suit.

Here’s how to get started with a MongoDB backed Drupal.


As it currently stands it is not possible for Drupal to run a pure MongoDB installation with Drupal. Drupal has made a lot of progress towards abstracting out database connectivity into a central model layer with Drupal 7 and Drupal 8 promises even more. However it is still a work in progress and while a majority of the functionality is available as MongoDB backed, as it stands today a few of the components remain dependant on SQL.

As most of the work to port Drupal to MongoDB has been towards scalability and performance, it is possible to have a site where public page views are 100% on MongoDB. Performance benchmarks on a MongoDB backed Drupal instance are quite impressive.

Installing MonogDB

These are the very brief instructions and make some assumptions. For more complete installation instructions please see the documentation.

Installing on linux

apt-get install mongodb-10gen or yum install mongodb

Installing on windows

Follow the install directions on the MongoDB site.

Installing on mac

brew install mongodb

Installing the MongoDB PHP driver

The complete directions can be found in the MongoDB PHP documentation.

Using Pecl to install the driver

Pecl is the preferred way to install the MongoDB driver. If you haven’t used pecl before, you may need to install some prerequisites first.

pecl install mongo

Configuring PHP to use the driver

Using your favorite editor add the following line to your php.ini file.

extension=mongo.so

Installing Drupal

This is the most complicated part and I will simply provide the excellent directions already given in the Drupal install.txt file with a few clarifications.

1. Download and extract Drupal.

You can obtain the latest Drupal release from http://drupal.org — the files
are available in .tar.gz and .zip formats and can be extracted using most
compression tools.

To download and extract the files, on a typical Unix/Linux command line, use
the following commands (assuming you want version x.y of Drupal in .tar.gz
format):

wget http://drupal.org/files/projects/drupal-x.y.tar.gz 

tar -zxvf drupal-x.y.tar.gz

This will create a new directory drupal-x.y/ containing all Drupal files and
directories. Then, to move the contents of that directory into a directory
within your web server’s document root or your public HTML directory,
continue with this command:

 mv drupal-x.y/* drupal-x.y/.htaccess /path/to/your/installation

2. Create the Drupal database.

Because Drupal stores all site information in a database, you must create
this database in order to install Drupal, and grant Drupal certain database
privileges (such as the ability to create tables). Currently this needs to be a relational database. Drupal supports SQLite, PostgreSQL and MySQL. For details, consult INSTALL.mysql.txt, INSTALL.pgsql.txt, or INSTALL.sqlite.txt. You may also
need to consult your web hosting provider for instructions specific to your web host.

Take note of the username, password, database name, and hostname as you
create the database. You will enter this information during the install.

3. Run the install script.

To run the install script, point your browser to the base URL of your
website (e.g., http://www.example.com).

You will be guided through several screens to set up the database, add the
site maintenance account (the first user, also known as user/1), and provide
basic web site settings.

During installation, several files and directories need to be created, which
the install script will try to do automatically. However, on some hosting
environments, manual steps are required, and the install script will tell
you that it cannot proceed until you fix certain issues. This is normal and
does not indicate a problem with your server.

Integrating MongoDB and Drupal

Installing the Drupal MongoDB plugin

The MongoDB Drupal plugin installs like any drupal plugin. Either install via the administration screen, or simply download the module at http://drupal.org/project/mongodb and uncompress it into the sites/all/modules/ directory.

Configure Drupal to use the MongoDB plugin

Currently there isn’t an admin interface to configure MongoDB, luckily it’s easy enough to configure manually.

First create a file called local.settings.php (it should be in the same directory as settings.php).

Populate the file with the following contents. Make sure to replace the placeholders [YOURDATABASENAME] and [SITENAME].

YOURDATABASENAME name can be anything doesn’t need to be created prior to use.
SITENAME will either be your sitename as it is named in Drupal. It may be called ‘Default’ if this is the primary site for the Drupal installation.

<?php
#MongoDB
$conf['mongodb_connections'] = array(
'default' => array( // Connection name/alias
'host' => 'localhost', // Omit USER:PASS@ if Mongo isn't configured to use authentication.
'db' => '[YOURDATABASENAME]' // Database name. Make something up, mongodb will automatically create the database.
),
);
include_once('./includes/cache.inc');
# -- Configure Cache
$conf['cache_backends'][] = 'sites/[SITENAME]/modules/mongodb/mongodb_cache/mongodb_cache.inc';
$conf['cache_class_cache'] = 'DrupalMongoDBCache';
$conf['cache_class_cache_bootstrap'] = 'DrupalMongoDBCache';
$conf['cache_default_class'] = 'DrupalMongoDBCache';
# -- Don't touch SQL if in Cache
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;
# Session Caching
$conf['session_inc'] = 'sites/[SITENAME]/modules/mongodb/mongodb_session/mongodb_session.inc';
$conf['cache_session'] = 'DrupalMongoDBCache';
# Field Storage
$conf['field_storage_default'] = 'mongodb_field_storage';
# Message Queue $conf['queue_default_class'] = 'MongoDBQueue';
?>

 

Enabling the MongoDB Module

Login to your drupal administration screen.

Navigate to the modules management screen.

First we need to disable the block module from Drupal Core. This will conflict with the MongoDB Block module and Drupal won’t let you enable the MongoDB plugin with this enabled. Uncheck Block and click save.

Now as the screenshot below demonstrates scroll to the bottom of the modules adminstration screen to the MongoDB section and enable all the modules.

Resources

  • http://chicago2011.drupal.org/sessions/practical-mongodb-and-drupal
  • http://cyrve.com/mongodb
  • http://www.slideshare.net/ForestMars/mongo-drupal
  • http://www.mongodb.org/display/DOCS
  • http://www.mongodb.org/display/DOCS/Quickstart+Windows
  • http://www.php.net/manual/en/mongo.installation.php
  • http://vim.spf13.com

 

Drupal MongoDB

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Path From APIs to Containers
  • How To Handle Secrets in Docker
  • Fargate vs. Lambda: The Battle of the Future
  • REST vs. Messaging for Microservices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: