Setup Drupal 7 Panopoly distribution with mongoDB on CentOS 7

The mongoDB provides high performance, high availability, and easy scalability. Using it with Drupal, will take some load off its SQL database. The read/write SQL procedures in Drupal functions like: session, log entries from watchdog, cache, fields, queue and block can be handled by mongoDB Drupal module. And this will greatly improve the perfomance of your Drupal site.

As of this writing the mongodb module is still in 7.x-1.0-rc2 version and obviously is not stable. Another is that this module does not run 100% mongoDB database on your Drupal and still some components are dependant on SQL.

We will take a look on how to setup mongoDB and integrate it with Drupal 7 Panopoly distribution. Panopoly profile is a very good building foundation for a Drupal site. The following procedures are tested on my Linode server running Centos 7 64-bit Linux distribution. And it is required that you have "drush" installed in your system.

Setup Mongodb service

  1. Use the mongoDB repo and configure the package management system to make it available in our yum:
    
    vi /etc/yum.repos.d/mongodb-org-3.0.repo
    
    

    ... and write the following as content of this repo file:

    
    [mongodb-org-3.0]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/
    gpgcheck=0
    enabled=1
    
    
  2. Execute the the following command to install mongoDB:
    
    yum install mongodb-org.x86_64
    
    
  3. Modify the mongod.conf:
    
    vi /etc/mongod.conf
    
    

    ... and add the following config items:

    
    auth=true
    smallfiles=true
    
    

    The "auth=true" to enable the security and "smallfiles=true" to solve this issue.

  4. Create a super user:
    
    mongo
    
    

    ... a mongoDB prompt will show and execute the following commands:

    
    use admin
    db.createUser(
      {
        user: "admin",
        pwd: "password",
        roles: [ "root" ]
      }
    )
    quit()
    
    

    Next time you login to your mongo command prompt, execute this command:

    
    mongo -u admin -p --authenticationDatabase admin
    
    
  5. Register mongoDB's log to logrotate:
    
    vi /etc/logrotate.d/mongodb
    
    

    Have the following scripts as content:

    
    /var/log/mongodb/*.log {
      daily
      rotate 30
      compress
      dateext
      missingok
      notifempty
      sharedscripts
      copytruncate
      postrotate
      /bin/kill -SIGUSR1 `cat /var/lib/mongo/mongod.lock 2> /dev/null` 2> /dev/null || true
      endscript
    }
    
    
  6. Run the mongoDB service:
    
    systemctl start mongod.service
    
    

Install mongodb PHP driver

  1. Install the tools for building PHP extensions:
    
    yum install php-devel php-pear
    
    
  2. Download the mongodb PHP driver from github:
    
    cd /opt
    git clone https://github.com/mongodb/mongo-php-driver
    
    
  3. Compile and install the mongodb PHP driver:
    
    cd mongo-php-driver
    phpize
    ./configure
    make
    sudo make install
    echo "extension=mongo.so" > /etc/php.d/mongo.ini
    
    
  4. Restart your web server:
    
    systemctl restart httpd.service
    
    

Setup mongoDB in Drupal

  1. Download Drupal 7 Panopoly distro into your web directory (in my case its "/home/webfoobar/public_html") and install it:
    
    cd /home/webfoobar/public_html
    drush dl panopoly-7.x-1.51
    mv panopoly-7.x-1.51/{.,}* .
    rm -rf panopoly-7.x-1.51
    cd profiles/panopoly/modules/contrib/devel
    curl https://www.drupal.org/files/issues/fatal-dd-2559061-12.patch | patch -p1
    drush si panopoly --account-name=admin --account-pass=password --db-url=mysql://admin:[email protected]/mydatabase
    
    

    Note: Ignore the errors. Those errors will not prevent us from running our Drupal site. The last command will create the "mydatabase" database automatically.

  2. Download and enable the mongodb module:
    
    cd ../../../../../sites/all/modules
    git clone --branch 7.x-1.x https://git.drupal.org/project/mongodb.git
    cd mongodb
    git checkout 006e78d07cc45817e6fcc7f4a2ddb17eb6220538
    curl https://www.webfoobar.com/sites/webfoobar.com/files/article_attachment/mongodb-fix-1961728.patch | patch -p1
    composer require alcaeus/mongo-php-adapter
    drush dis block
    drush en mongodb mongodb_block_ui mongodb_watchdog mongodb_field_storage mongodb_session mongodb_cache mongodb_queue mongodb_block mongodb_migrate
    
    

    Note: Ignore the errors. Those errors will not prevent us from running our Drupal site.

  3. Edit your Drupal settings file:
    
    vi ../../../default/settings.php
    
    

    ... and append these PHP codes:

    
    /**
    * MongoDB configurations
    */
    $conf['mongodb_connections'] = array(
      // Connection name/alias
      'default' => array(
        // Omit USER:[email protected] if Mongo isn't configured to use authentication.
        'host' => 'mongodb://admin:[email protected]',
        // Database name
        'db' => 'mymongodatabase',
      ),
    );
    #$conf['mongodb_debug'] = TRUE;
    $conf['cache_backends'][] = 'sites/all/modules/mongodb/mongodb_cache/mongodb_cache.inc';
    $conf['cache_default_class'] = 'DrupalMongoDBCache';
    // The 'cache_form' bin must be assigned to non-volatile storage.
    $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
    // Don't touch SQL if in Cache
    $conf['page_cache_without_database'] = TRUE;
    $conf['page_cache_invoke_hooks'] = FALSE;
    $conf['field_storage_default'] = 'mongodb_field_storage';
    $conf['mongodb_watchdog'] = 'watchdog';
    $conf['mongodb_watchdog_items'] = 10000;
    $conf['watchdog_limit'] = WATCHDOG_ERROR;
    $conf['mongodb_session'] = 'session';
    $conf['session_inc'] = 'sites/all/modules/mongodb/mongodb_session/mongodb_session.inc';
    $conf['cache_session'] = 'DrupalMongoDBCache';
    
    

    Note: Make sure to change the "host" and "db" with your mongodb credentials and database.

  4. Run the drush commands to migrate the Drupal fields:
    
    drush mongodb-migrate-prepare
    drush mongodb-migrate
    
    
  5. Congratulations! Login to your new Drupal 7 Panopoly with mongoDB backed site.

You may want also to check this article: Setup Rock Mongo web interface.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.