Drupal to the cloud: Making the shift from LAMP to Windows Azure

Author: Ben Lobaugh <ben@lobaugh.net>

Date: Monday, October 10, 2011, 4:31:36 PM

Tags: Scenario, Drupal

Table of Contents

Note:This article pertains to the CodePlex SDK initially released late 2009. The Windows Azure team has since then released a newer version of the Azure SDK for PHP on Github. Please refer to the Windows Azure PHP Developer Center for documentation on this more recent version of the SDK.

Please stay tuned and come back here regularly as we are working on refreshing the tutorials to deliver up to date and useful content for our PHP developers.

Pre-Requisites

Synopsis

This documentation will show you, how to move your Drupal site from the LAMP environment to Windows Azure.

Steps to move LAMP based Drupal to Windows Azure

Step 1: Export the db in portable format

The purpose of this step is to get the portable cross-database dumps of your current Drupal website. Once we get the database dump we can easily import this to any database that is supported by Drupal.

The export operation can be done from the ; existing site, it can be Linux or Windows. The export process does not write anything to DB or modify the Drupal site file so there is no harm to the existing site. But the import operation can be done only from a Windows machine since we are moving to SQL Server.

The tool we are using to perform export/import operation is the Drush.

Drush

Drush is a command line shell and scripting interface for Drupal.

Installing Drush on Linux

Refer this link to install Drush on Linux.

Installing Drush on Windows

Download Drush for Windows from this link and install it on your machine.

Once you have installed Drush on your machine, the installation folder look similar to the following:

image

Next add the Drush executable path to the Windows PATH variable.

Ensure the Drush is working properly by opening a command prompt window and type the command "drush" it should list all the available Drush commands.

Getting portable database dump commands

Inside Drush you can see a commands folder where you can keep your own custom commands.Portable database dump commands are missing by default, so you have to download it manually, and unzip it to the commands folder.

After unzipping it to the commands folder, the expanded commands folder structure will be as follows:

image

Make sure that the Drush command list contains the portabledb-export, portabledb-import commands by executing the command "drush".

Executing the export command

In the command prompt cd to the root of your Drupal installation and run the following command to export your database

Run the following command to export the database:

drush portabledb-export --use-windows-azure-storage=true --windows-azure-stream-wrapper-name=azurepublic --windows-azure-storage-account-name=<your azure storage account name> --windows-azure-storage-account-key=<your azure storage account key> --windows-azure-blob-container-name=<your azure storage container name> --windows-azure-module-path=sites/all/modules --ctools-module-path=sites/all/modules > mysite.dump

Step 2: Import the db dump to SQL Server

If you run the export operation on Linux you have to setup the site on windows machine for the import operation, this is because you will be importing to SQL Azure which uses the SQL server module that is not currently available in Linux.

You can either import to your SQL Azure DB or you can import to your local SQL Server and then migrate the local SQL Server data to SQL Azure DB. Since the import operation takes several minutes there can be chance for connection timeout if you are trying to directly import it to SQL Azure, therefore it is recommend to first import to your local SQL Server and them migrate the data.

You will need to update the database settings in site/default/settings.php

If you choose to import to a local SQL Server your settings will be similar to the following:

$databases = array (
    'default' => array ('default' => array ('database' => 'your Drupal db name',
                                            'username' => 'your SQL Server username',
                                            'password' => 'your SQL Server password',
                                            'host' => 'localhost',
                                            'port' => '',
                                            'driver' => 'sqlsrv',
                                            'prefix' => '',
                        ),

    ),
);

If SQL Server driver is missing in your Drupal installation download it from this link and unzip it to the includes/database folder.

Add the Windows Azure SDK for PHP library path to your php.ini

The Drush import tool relies on the Windows Azure SDK for PHP and should be added to the include_path in the php.ini file.

  • Edit your php.ini file
  • Locate the include_path line
  • Append the location of the Windows Azure SDK for PHP, which will most likely be C:\Program Files\Windows Azure SDK for PHP\library
  • Save the php.ini file

Your include_path may look similar to the following:

include_path = ".;C:\PHP\pear;C:\Program Files\Windows Azure SDK for PHP\library"

Executing the import command

The command to import the db is

drush portabledb-import --delete-local-files=true --copy-files-blob-storage=true mysite.dump

Running the import operation may take several minutes. It is inserting all the data to your SQL Server DB, and uploading the sites/default/files to azure blob storage.

Step 3: Update image module to the latest version

Update the core image module to the latest version to avoid any error related to DrupalAzureStorageStreamWrapper. It is always better to update the themes and modules before it is being packaged.

Step 4: Use the Drupal scaffold to deploy your Drupal site to Azure

Next we are going to package current Drupal site to deploy it to azure, using the scaffolding features of the Windows Azure SDK for PHP.

Internet access is required for the Drupal scaffold to download several core components.

Download the Drupal scaffold

The Drupal scaffold can be downloaded from:

https://github.com/Interop-Bridges/Windows-Azure-PHP-Scaffolders/tree/master/Drupal

Or

https://github.com/downloads/Interop-Bridges/Windows-Azure-PHP-Scaffolders/drupal.zip

Once you unzip the downloaded package the folder structure is as below:

image

Build the scaffolder

The source folder contains the source of the scaffold which you can download and alter as need requires.

Since we are deploying an existing website, copy the all your Drupal files to the source\resources\WebRole folder.

Note: Replace your drupal settings.php with the settings.php available in source\resources\WebRole\sites\default folder of the Drupal scaffolder. It is using azure_getconfig () API to read the correct settings available in ServiceConfiguration.cscfg file.

Next execute build_scaffolder.bat command. This will produce drupal.phar file in current directory.

image

Run the scaffolder

Edit run_scaffolder.bat and replace ***** with correspnding values for your SQL Azure and Windows Azure storage credentials.

Execute run_scaffolder.bat. It will create .\build\drupal folder containing all files needed for packaging.

image

Running the Drupal scaffold may take several minutes. There are several critical operations happening:

  • A Drupal archive is downloaded and unpacked into the project directory
  • The plugin for SQL Azure is downloaded and added to the project
  • The Windows Azure Integration module is downloaded and added to the project
  • Drupal is configured to work with Windows Azure services
  • The Windows Azure service configuration file is setup

The build\drupal folder will contain the following files:

image

The Drupal files are located inside of the WebRole folder.

If you want to add any new modules, themes, installation profiles add them now before it is packaged and uploaded.

You can add them in the following folders:

  • .\build\drupal\WebRole\sites\all\modules
  • .\build\drupal\WebRole\sites\all\themes
  • .\build\drupal\WebRole\profiles

Modify SQL Azure and Windows Azure storage credentials

If you want to modify the SQL Azure and Windows Azure storage credentials provided while executing run_scaffolder.bat command you can manually edit this in .\build\drupal\ServiceConfiguration.cscfg file.

Change the default VM size

If you need to change the default VM size, you can update vmsize attribute in following line in .\build\drupal\ServiceDefinition.csdef file.

<WebRole name="WebRole" enableNativeCodeExecution="true" vmsize="Small">

Allowed values for vmsize attribute are "ExtraSmall", "Small", "Medium", "Large" and "ExtraLarge".

Enable RDP access

If you need to enable RDP access, you need to

  • Uncomment following lines from .\build\drupal\ServiceDefinition.csdef file
    <Import moduleName="RemoteAccess"/>
    <Import moduleName="RemoteForwarder"/>
    
  • Uncomment following lines from .\build\drupal\ServiceConfiguration.cscfg file
    <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
    <Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
    <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" value="****" />
    <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" value="****" />
    <Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" value="2039-12-31T23:59:59.0000000-08:00" />
    

Custom php.ini settings

If you need to add or change custom settings in the php.ini file this scaffold has support for that. Open the WebRole directory and you will find a php directory. Inside of that directory is a php.ini file. Whatever settings exist in here are automatically added to the installed PHP's php.ini at runtime.

Additionally if you have extension you would like to run they may be added to the ext folder and setup in the php.ini. All files in the ext folder are copied to the installed PHP's ext folder at runtime and will be available for use.

Install Windows Azure FileSystemDurabilityPlugin

Once you are done with the customization you have to install Windows Azure FileSystemDurabilityPlugin. The Windows Azure FileSystemDurabilityPlugin ensures that newly added themes/modules on running Drupal site are synchronized across all running instances.

Download the FileSystemDurabilityPlugin and extract the folder to C:\Program Files\Windows Azure SDK\<YOUR VERSION>\bin\plugins.

Now we are ready for packaging.

Package the scaffolder

Execute the package_scaffolder.bat command. It will create following two files inside package folder

  • \package\drupal.cspkg
  • \package\ServiceConfiguration.cscfg

Deploy the Drupal package

Now you can deploy your Drupal package to Windows Azure.

Refer this link to deploy through portal.

You can refer this link for a detailed documentation of How to deploy Drupal to Windows Azure using the Drupal scaffold.

Step 5: Check the website is working properly

Visit the URL you chose when creating the Hosted Service which the Drupal package is deployed on and make sure that website is working properly.

Step 6: Manually edit the images that are pointing to windows filesystem

In Drupal some contents will be saved as html in the database, and there may be image links in the html will be pointing to local filesystem (not to azure blob storage), in order to point these images to Windows Azure blob storage you have to manually edit the contents from the Drupal back end.

Enjoy Drupal!

At this point your Drupal website should be up and running. Enjoy your new website

 
blog comments powered by Disqus