Amazon AWSThe affordability, availability, and scalability of cloud hosting has made it popular among individuals and companies of all sizes. Leading the way is Amazon Web Services (AWS). We've evaluated the pros and cons of setting up Drupal on Amazon AWS, and found that running an optimized Drupal stack with AWS can be very affordable and simple to set up. Here, I will show how to set up an optimized Drupal server using AWS.

Initial Server Setup and Configuration

First you will need to create an account at Once your account is created, login to the management console. From there, you can access all your services.

Launching a New Server

Once in the dashboard, open EC2 and select launch instance. A dialog will display to step you through the process. Select the classic wizard and you will have a list of choices similar to the ones displayed below.


I prefer the Ubuntu version of Linux due to the large number of packages available in the repository. So, from here select the Ubuntu Server LTS option with 64-bit selected. On the next screen, select the instance type from the dropdown in the upper right. The costs associated with each instance type can be found on Once you have selected your instance type, click on the continue button to move to the next screen.

The next screen has some details regarding the Linux kernal, RAM disk ID, user data, etc. You don’t need to make any changes on this screen, so move on to the next one.

The next screen is the storage device configuration setup. The mounted drives are detailed in the table displayed. Again, you don’t need to make changes here, so move on to the next screen.

This screen allows you to add tags to the instance. These are useful to identify different servers on the EC2 dashboard. The default name key is used for this purpose.

The key pairs screen is where you can add a new key pair or select an existing one to connect to the server. To create a new key pair, enter a name in the text box, then select download. The key goes in the “.ssh” folder for a user on your local computer. Make sure to make a backup of the key because if lost, you will not be able to login to your server.

The security groups screen is where you can select or modify firewall rules. Make sure to add rules for port 80 (HTTP), and 22 (SSH).

On the last screen, you can review all the details of the instance about to be created. Once everything looks good, click on the launch button, and the instance with be created. Typically, the instance will be ready in 30 - 60 seconds.

Setup and Attach Additional Storage

Before connecting to the server, we need to setup any additional volumes need from the Elastic Block Store (EBS). These volumes attach to the server as additional drives. I like to use these for database files, web files, and sometimes log files. The EBS volumes are redundant and persistent. In the case the instance has a hardware failure, EBS will detach and wait to be connected with a new instance.

In the dashboard, select volumes under the elastic block store heading. Click on the create volume button to bring up a dialog.

Select standard as the volume type and enter the amount of storage needed. In the availability dropdown, you will need to select the same zone the instance was create in. The instance zone can be found when looking at the instance details.

Next, right click on each new EBS volume and select attach. This is where you can attach the volume to the server instance. Make sure to set a unique name for each volume. For example, if the first is set to “/dev/sdf”, then set the second to “/dev/sdg”, and so on.

Connect to the Server

Next, connect to the server via ssh. The username for the instance is initially set to “ubuntu”. Initially, you can connect with the public dns setup by Amazon, then once the server is setup, use the elastic ip address or a url pointing to the server.

ssh [email protected][public dns/elastic ip/hostname] -i ~/.ssh/[name of key file]

Install Software Updates

After logging into the server, the next step is to update the system software packages. This is accomplished using the apt-get package manager. Run the following commands to update.

sudo apt-get update
sudo apt-get dist-upgrade

Format and Mount EBS Volumes

Now, we need to format and found the created EBS volumes, but first, create a location for each volume you created and change ownership to the "ubuntu" user.

sudo mkdir /www
sudo mkdir /db
sudo chown ubuntu:ubuntu /www /db

Format each drive with the ext4 file system. Ubuntu will change the name of an attached drive. For example, if the attached location is “/dev/sdf”, Ubuntu will name it “/dev/xvdf”.

sudo mkfs.ext4 /dev/xvdf
sudo mkfs.ext4 /dev/xvdg

Add each volume to /etc/fstab. This will mount the EBS volumes after a reboot and at the specified location.

/dev/xvdf	/www	auto	defaults,nobootwait,noatime	0	0
/dev/xvdg	/db	auto	defaults,nobootwait,noatime	0	0

Run the following command to mount the volumes without having to reboot.

sudo mount -a

Install Software Packages

Now it is time to install all the other software needed for a Drupal site to function. Most of the installation is straightforward, with the exception of varnish, where you will need to add an external repository to apt-get.

Install Apache.

sudo apt-get install apache2

Install MySQL. You will be prompted to enter the root user password. Make sure it is a strong password.

sudo apt-get install mysql-server

Install PHP5 and APC. APC stands for alternative php cache and helps to speed up PHP by caching compiled code.

sudo apt-get install php5 php5-gd php5-mysql php-apc

At this point, you have installed all the software needed to run a Drupal site. For faster page load response times, we need to install some additional software to cache requests in memory.

Install memcached.

sudo apt-get install memcached libmemcached-tools php5-memcached

We need to add a repository to apt-get before we can install varnish. To do that, run the following commands.

curl | sudo apt-key add -
echo "deb precise varnish-3.0" | sudo tee -a /etc/apt/sources.list

Now we are ready to install varnish.

sudo apt-get update
sudo apt-get install varnish

Drush is a very useful tool for Drupal administration from the command line. To install, copy the url from and then run the commands below from the home directory.

wget [drush url]
tar -xvzf [name of drush file]
sudo ln -s /home/[user name]/drush/drush /usr/bin/drush

That’s it for the software install. Now we can move on to configuration.

Software Configuration

Some of the installed packages above require little to no configuration, while others require quite a bit. We will go through each of them here.

Apache Configuration

The first thing we need to do is enable the necessary apache modules for Drupal.

sudo a2enmod rewrite expires headers

Change apache to listen on port 8080 instead of 80. Varnish will run on port 80 and forward non-cached requests to apache. Edit the file at /etc/apache2/ports.conf. Change the following values in the configuration file.

NameVirtualHost *:8080
Listen 8080

Change default vhost file. Edit the file at /etc/apache2/sites-available/default and change the following.

*:80 to *:8080
AllowOverride None to AllowOverride All
All instances of /var/www to /www

Last, restart the apache server to load the changes.

sudo service apache2 restart

MySQL Configuration

There are some changes we need to make to the MySQL configuration to optimize performance and provide more redundancy in data storage. Let’s start by creating our own configuration file for MySQL at /etc/mysql/conf.d/local.cnf. Add the following lines:

bind-address = [internal or elastic ip]
tmpdir = /run/mysqld

The bind-address property needs to be changed to if you intend to use external tools to administer and backup databases. The tmpdir property specifies the location for MySQL temporary storage in memory, rather than on disk.

Next, let’s move the mysql table storage to an EBS volume. First, stop the mysql service.

sudo service mysql stop

Move the database files and create a symbolic link from the old location.

sudo mv /var/lib/mysql /db
sudo ln -s /db/mysql /var/lib/mysql

Update apparmor configuration at /etc/apparmor.d/usr.sbin.mysqld.

Change /var/lib to /db
Add new line /run/mysqld/ rw,

Start the mysql service.

sudo service mysql start

Memcached Configuration

After installing memcached, make sure the module is enabled in /etc/php5/conf.d/memcache.ini. There should be a line that reads:

Now, we need to update the amount of memory used by memcached. Edit the file at /etc/memcached.conf. Change the line “-m” to whatever value is appropriate for your server.

Restart apache and memcached.

sudo service memcached restart
sudo service apache2 restart

There are a couple of steps to integrate Memcached with Drupal. We will get to those steps a little later.

Varnish Configuration

To configure varnish, we need to edit a couple of files. The first is located at /etc/default/varnish. Scroll down to where you see the following five lines. Change the port on the first line to 80 and the amount of memory used on the last line to a level appropriate for your server.

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

Next, edit the file at /etc/varnish/default.vcl and replace with a Drupal optimized version located at

At the top of the file, you will notice the following lines.

backend default {
  .host = "";
  .port = "8080";

Change host to the assigned internal or elastic ip. If you are using a different port for apache, change the port to that number.

Restart apache and varnish.

sudo service apache2 restart
sudo service varnish restart

Install and configure Drupal

In the apache configuration section, we had set the web root directory to /www. Now, we are ready to install and configure Drupal using drush. Start by navigating to the /www directory and downloading Drupal.

drush dl drupal

Copy the files from the created directory to the current directory, then delete the directory created by drush. Copy the default.settings.php file to settings.php in sites/default and make the file user writable.

Create a database for the new site.

mysql -u root -p
create database [database name]

Open a browser using the public DNS, elastic IP, or hostname and follow the instructions to install Drupal. Once installed, we need to edit the settings.php file. Add the following lines.

$conf[‘cache_backends’][] =[path to memcache module]/’;
$conf[‘cache_default_class’] = ‘MemCacheDrupal’;
$conf[‘memcache_key_prefix’] =[unique prefix];

That’s it for the installation and configuration of Drupal on your new AWS server.