You are here

Running Drupal 7 on a NuoDB Database

Drupal IconDrupal 7 is a popular web content management system and web application framework that is written in PHP. I implemented a NuoDB Drupal 7 database driver that allows customers to run Drupal 7 web applications on a NuoDB database. We use Drupal on NuoDB to run our corporate website. In this techblog, I will explain how the Drupal database abstraction layer works, introduce you to the NuoDB Drupal driver, and then show you how you can use NuoDB to build your own Drupal 7 applications.  

Drupal's Database Abstraction Layer

Drupal 7 contains a database abstraction layer that is supported by a wide variety of SQL databases (MySQL, PostgreSQL, SQLite, Microsoft SQL Server, Oracle) and now is supported by NuoDB. Drupal's database layer is built using PHP PDO and a database specific Drupal driver. PHP PDO provides a unified object-oriented API for accessing databases, but does not provide an abstraction for the varying SQL dialects and metadata used by different databases. To provide that, the Drupal database abstraction layer requires a Drupal driver for each database type.

NuoDB already has a NuoDB PHP PDO driver, which I covered in my previous techblog articles (NuoDB for PHP, NuoDB: How to Turn LAMP into a Powerful, Scale-out Software Bundle, CodeIgniter - Fired Up on NuoDB). To support Drupal 7, I wrote a NuoDB Drupal 7 driver. The NuoDB Drupal driver is open source, written in PHP, and stored in a Git repository on Drupal.org. The driver handles the database aspects that are specific to NuoDB, including connections, schema, type mapping, key, SQL statements, and database metadata operations.  Here's a picture of the Drupal layers that are involved with using NuoDB:

Drupal Database Layers with NuoDB

Installing PHP and a Web server

In this example, I will show you how to setup Drupal 7 on NuoDB, using a clean Linux Mint 17 machine. The first thing you need to do is to install PHP and a web server using the following commands. For this example, we will use Apache2 for the web server.


 
sudo apt-get install php5
sudo apt-get install php5-gd

Disable Transparent Huge Pages

Next you need to disable transparent huge pages, because it is required by NuoDB. To do that on Linux Mint 17, you need to edit  /etc/rc.local to contain the following and then reboot your system:


 
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
  echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
  echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
if test -f /sys/kernel/mm/redhat_transparent_hugepage/enabled; then
  echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/redhat_transparent_hugepage/defrag; then
  echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag
fi

 

Download, configure, and start NuoDB

Then download the NuoDB Ubuntu/Debian package from the nuodb.com website: http://www.nuodb.com/download and install it using the following command:


 
sudo dpkg -i $HOME/Downloads/nuodb_2.1.1.13_amd64.deb

Then we need to edit the NuoDB default.properties to provide a domain password (we will use the password "domain_password") and then start the NuoDB services:


 
sudo sed -i 's/#domainPassword =/domainPassword = domain_password/g' /opt/nuodb/etc/default.properties
sudo service nuoagent start
sudo service nuorestsvc start

Download Drupal 7

Next we need to download Drupal 7 and put a copy in the /var/www directory:


 
cd /tmp
wget http://ftp.drupal.org/files/projects/drupal-7.34.tar.gz
cd /var/www
sudo tar -xzf /tmp/drupal-7.34.tar.gz
sudo mv drupal-7.34 drupal_nuodb

Install NuoDB Drupal 7 Driver

Then we need to install git, download the NuoDB Drupal 7 driver from drupal.org, and copy it into the Drupal 7 directory:


 
sudo apt-get install git
cd /tmp
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/tgates/2191439.git _d7__nuodb_driver
cd /var/www/drupal_nuodb/includes/database/
sudo cp -r /tmp/_d7__nuodb_driver/nuodb .

Next, we will create a PHP script that we can use to show us the configuration of the PHP that is installed:


 
cat  EOF > /tmp/phpinfo.php
phpinfo();
?>
EOF
sudo cp /tmp/phpinfo.php /var/www/html

At this point, you can open a web browser to URL localhost/phpinfo.php and it should show the current PHP configuration on your machine.

NuoDB PHP PDO driver

Now we need to install and configure the NuoDB PHP PDO driver. There is a pre-built driver for PHP 5.5.NTS, which matches the PHP version that is installed by Linux Mint 17. You can install it with the following commands:


 
sudo cp /opt/nuodb/drivers/php_pdo/php-5.5.NTS/pdo_nuodb.so /usr/lib/php5/20121212
cat  EOF > /tmp/pdo_nuodb.ini
extension=pdo_nuodb.so
pdo_nuodb.enable_log=1
pdo_nuodb.log_level=1
pdo_nuodb.logfile_path=/var/log/nuodb_pdo.log
EOF
sudo cp /tmp/pdo_nuodb.ini /etc/php5/apache2/conf.d
sudo service apache2 restart

Configure Apache2

Browsing localhost/phpinfo.php should show you the NuoDB PHP PDO driver. Next we need to create an Apache2 configuration for the Drupal application. You can do that with the following:


 
cat  EOF > /tmp/drupal_nuodb.conf
VirtualHost *:80>
  ServerName drupal_nuodb
  DocumentRoot /var/www/drupal_nuodb
  Directory "/var/www/drupal_nuodb">
    AllowOverride All
  Directory>
VirtualHost>
EOF
sudo cp /tmp/drupal_nuodb.conf /etc/apache2/sites-available
sudo sed -i '$ a\127.0.0.1 drupal_nuodb' /etc/hosts 
sudo chown -R www-data:www-data /var/www/drupal_nuodb
sudo a2ensite drupal_nuodb
sudo service apache2 reload

Creating a NuoDB database

Now we need to create a NuoDB database for our Drupal application. You can do that using a web browser with the URL: localhost:8888 and then click the icon for the "Automation Console":

Then you need to login using the domain username "domain" (which is the default username) and domain password "domain_password" that we set in a previous step:

At this point, you can click on the "Databases" icon on the left side, and then click "Actions" and "Add Database" on the right hand side:

For our example Drupal application, we will enter the database name "drupal_nuodb", DBA user "dba_user", and DBA password "dba_password" as follows and click the button to create the database.

At this point, we have an empty "drupal_nuodb" database, and we can run the Drupal installer by opening a web browser on the URL: drupal_nuodb. Follow the on screen instructions until you get to the Drupal "Database configuration" page. For the Drupal database name use "drupal_nuodb@localhost" because "drupal_nuodb"  is the database name that we created above, and the NuoDB Broker for that database is running on the "localhost". Also enter the database username "dba_user" and database password "dba_password" that we used in the previous step:

Be sure to follow the on-screen instructions to complete the Drupal install.

Drupal's transaction isolation requirements

Drupal 7 expects the database to have transaction isolation level of ReadCommitted. NuoDB's default transaction level is ConsistentRead. To change NuoDB to use ReadCommited with Drupal, modify your site's settings.php by running the following commands:


 
sudo su -
cat  EOF >> /var/www/drupal_nuodb/sites/default/settings.php
\$databases['default']['default']['init_commands'] = array(
  'isolation' => "SET ISOLATION LEVEL READ COMMITTED;"
);
EOF

Now you have a Drupal 7 Web application running on NuoDB! 

At this point you can build your Drupal 7 application just like any other. In my next techblog, I want to show you how to migrate an existing Drupal 7 application from MySQL to NuoDB. We use Drupal 7 for our corporate website. That website was initially running on MySQL, and we migrated it to run on top of NuoDB. I will show you how to do the same in an upcoming blog post. 

Add new comment