SlideShare a Scribd company logo
Moving Drupal to the Cloud:
        A step-by-step guide and reference document for
       hosting a Drupal web site on Amazon Web Services
                                   MCN 2009: Cloud Computing Primer Workshop

                                             Charles Moad <cmoad@imamuseum.org>
                                            Robert Stein <rstein@imamuseum.org>
                                               Ari Davidow <adavidow@jwa.org>




INTRODUCTION ........................................................................................................................................ 2
    CONVENTIONS USED IN THIS DOCUMENT ................................................................................................... 2
    EC2 CONSOLE ............................................................................................................................................ 3
PREREQUISITES TO LAUNCHING AN EC2 INSTANCE .................................................................. 4
    CREATING A KEY PAIR ............................................................................................................................... 4
    CREATING A SECURITY GROUP .................................................................................................................. 5
    SELECTING A STARTER AMI ...................................................................................................................... 6
LAUNCHING AND CONNECTING TO YOUR EC2 INSTANCE........................................................ 7
    STARTING YOUR EC2 INSTANCE ................................................................................................................ 7
    CONNECTING TO YOUR EC2 INSTANCE ...................................................................................................... 8
      Preparing Your SSH Key Pair for Putty ............................................................................................... 8
CONFIGURING YOUR EC2 INSTANCE ................................................................................................ 9
    INSTALLING PREREQUISITES ....................................................................................................................... 9
    CREATING AN EBS VOLUME .................................................................................................................... 10
    ATTACHING YOUR EBS VOLUME............................................................................................................. 11
    FORMATTING AND MOUNTING YOUR EBS VOLUME ................................................................................ 11
    CONFIGURING MYSQL............................................................................................................................. 12
    CONFIGURING APACHE............................................................................................................................. 13
INSTALLING AND CONFIGURING DRUPAL.................................................................................... 14
APPENDIX ................................................................................................................................................. 15
    CONFIGURING CRON FOR DRUPAL .......................................................................................................... 15
    ASSIGNING A STATIC IP TO YOUR EC2 INSTANCE.................................................................................... 16
    SNAPSHOTTING YOUR EBS ...................................................................................................................... 17
    BUNDLING YOUR EC2 INSTANCE INTO AN AMI....................................................................................... 18




                                                                                                                                        Page 1 of 19
Introduction
This document aims to give attendees a step-by-step guide on how to host a Drupal
website using the Amazon Web Services. It should also serve as a valuable reference
document. The Drupal instance will be hosted on a LAMP stack and steps will be shown
on how to backup and snapshot your EC2 instance.

Conventions Used in this Document
   •   Normal text
   •   Filename or itemname
   •   Command line




                                                                        Page 2 of 19
EC2 Console
This guide uses the EC2 Console, a web interface provided by Amazon which allows
complete control of running and managing EC2 instances in the cloud.




                                                                        Page 3 of 19
Prerequisites to Launching an EC2 Instance
Creating a Key Pair
You must specify a security key pair to use when launching EC2 instances. A key pair is
actually used as your SSH key pair for connecting to your instance. There is no password
access. You can technically launch an instance without a key pair, but then you would
have no means to log into the running instance.

In the EC2 console, select Key Pairs from the Navigation section. Click the Create Key
Pair button to create a new key pair. In this example we will name our key pair, mcn09.
Once you create your key pair, your browser will download the actual private key file. In
this example the file will be named, mcn09.pem. Keep this file secure.




                                                                            Page 4 of 19
Creating a Security Group
Think of security groups simply as your firewall rules for EC2 instances. You use it to
say which ports are open, and who they are open to. You must specify a security group
when launching an EC2 instance. At a minimum, you will want to allow access on port
22 so you can SSH and port 80 to serve web pages.

In the EC2 console, select Security Groups from the Navigation section. Click the Create
Security Group button to create a new group. In this example we will name our security
group, mcn09. Optionally enter a description for the group.




Configure the ports as shown in the image below. Fill in each line and click Save. The
Source item should be set to 0.0.0.0/0 to allow access to allow machines. Reference
CIDR Notation to learn more about this setting or click the Help button seen in the
interface below.




                                                                            Page 5 of 19
Selecting a Starter AMI
You’ll need to select an Amazon Machine Image to use as a basis for your EC2 instance.
There exists AMI’s preconfigured with Drupal. This guide however will use a stock,
Amazon provided Fedora 32-bit AMI. Specifically we are using, ami-48aa4921, as
shown below.




EC2 has a variety of instance sizes that you can launch your AMI’s on. They vary in
storage, memory, priority, processing power, and most namely, price. m1.small and
c1.medium instance sizes are 32-bit and can only run 32-bit AMI’s. All remaining
instance sizes are 64-bit. Several studies have shown that the c1.medium instance size is
by far the best bang for your buck. It is strongly recommended that you use this size for
moderate traffic LAMP web sites.




                                                                             Page 6 of 19
Launching and Connecting to Your EC2 Instance
Starting Your EC2 Instance
You are now ready to launch your EC2 instance. After selecting the AMI (ami-
48aa4921), click the Launch button. Fill in the form as shown in the image below. Most
importantly, select the mcn09 key pair and mcn09 security group that you have already
configured. In this example, we are launching a single m1.small instance.




In the EC2 console, click the Instances link in the Navigation section. Here you can
monitor the progress of your instance. Proceed once the status says, running. In this
example, our launched instance has the identifier, i-58d96330.




                                                                             Page 7 of 19
Connecting to Your EC2 instance
First you must get the public DNS name assigned to your new instance. You can find
this in the instance details of the EC2 Console. In this example, our public DNS is ec2-
67-202-9-72.compute-1.amazonaws.com.

If you are on a Linux or OSX machine, you can now SSH to your machine using the
following command in a terminal. If you are using Windows, follow the instructions for
preparing your SSH key pair for Putty.
   ssh –i mcn09.pem root@ ec2-67-202-9-72.compute-1.amazonaws.com

Preparing Your SSH Key Pair for Putty
If you are using Windows, you must first convert your key pair file to work with Putty. If
you are on a Linux or OSX machine, simply skip this section.

From the Start Menu, launch the PuTTYgen program under the PuTTY menu item. Select
Load private key from the File menu. Navigate and select the private key pair file you
downloaded earlier. In this example, the file name was mcn09.pem. Select Save private
key from the File menu. In this example, we name the new file mcn09.ppk. Now you can
connect to your running EC2 instance from Putty by providing this key pair file under
Connection SSH Auth. Use the username, root.




                                                                             Page 8 of 19
Configuring Your EC2 Instance
Installing Prerequisites
The AMI you started with have next to nothing installed. You must now install the
traditional LAMP stack as well as a few additional tools for Drupal.

Now you should run the following two commands to install our LAMP stack and some
other useful tools.
   yum groupinstall "MySQL Database" "Web Server"
   yum install php-gd xfsprogs phpMyAdmin

This will install Apache and MySQL as well as the library php-gd to make Drupal happy.
phpMyAdmin is an extremely useful web interface for administering MySQL.
Additionally we install xfsprogs so we can manipulate XFS file systems. All web and
database files will be hosted on an Elastic Block Store (EBS) volume that you will attach
to your running instance. The XFS file system is an ideal format for this volume since it
can be resized in case you need more space later, and it can be frozen which prevents
corrupt database files when snapshotting the volume. This will be discussed later in the
document.




                                                                            Page 9 of 19
Creating an EBS Volume
Storage on EC2 instances is considered ephemeral, meaning that it goes away when your
EC2 instance goes away. If for some reason your instance crashed, you would lose all of
your web and database files. To solve this problem, Amazon offers virtual block devices
you can attach to your running EC2 instances. Elastic Block Store (EBS) volumes can
range from 1GB to 1TB in size. These volumes are separate from your instance. They
remain persistent if your instance is terminated. You can detach an EBS volume from
one instance and attach it to another. Also, you can attach multiple EBS volumes to one
instance and even setup RAID configurations amongst those volumes.

You must first note which availability zone your instance is running in. EBS volumes
can only be attached to instances running in the same zone. You can find this in the
instance details of the EC2 Console. In this example, our instance is running in zone us-
east-1a. In the EC2 Console, click on Volumes in the Navigation section. Click the
Create Volume button to start the creation process. Make the EBS volume a reasonable
size and in the same zone as your EC2 instance. Leave Snapshot set to No Snapshot.




                                                                            Page 10 of 19
Attaching Your EBS Volume
Once the EBS volume is finished creating you will attach it to your running EC2
instance. In the EC2 Console, make sure you are still in the Volumes section. Click the
newly created EBS volume (vol-f5c6399c in this example) then click the Attach Volume
button. Select the EC2 instance you just launched and the device location you want the
volume to be mounted. In this example, we select our instance, i-58d96330, and the
default device location, /dev/sdf.




Formatting and Mounting Your EBS Volume
You will now need to format and mount your EBS volume on your EC2 instance. In this
example, you are mounting the volume at /ebsvol. We will also add an entry to /etc/fstab
so the volume will be automatically mounted in the event of a reboot. Run the following
commands in a terminal connected to your instance.
   mkdir /ebsvol
   mkfs.xfs /dev/sdf
   echo "/dev/sdf /ebsvol xfs noatime 0 0" >> /etc/fstab
   mount /ebsvol/




                                                                           Page 11 of 19
Configuring MySQL
The MySQL database and log files will reside on the EBS volume. You must now
configure MySQL to know where to host these files. First, create the destination
directories on the EBS volume.
   mkdir -p /ebsvol/mysql/lib/mysql
   mkdir -p /ebsvol/mysql/log/mysql

Edit the file, /etc/my.cnf, to contain the following.
   [mysqld]
   #datadir=/var/lib/mysql
   socket=/var/lib/mysql/mysql.sock
   user=mysql
   # Default to using old password format for compatibility with mysql 3.x
   # clients (those using the mysqlclient10 compatibility package).
   old_passwords=1
   innodb_file_per_table
   datadir          = /ebsvol/mysql/lib/mysql
   #log_slow_queries = /ebsvol/mysql/log/mysql/mysql-slow.log
   #long_query_time = 10
   max_connections = 250
   max_user_connections = 250
   key_buffer = 36M
   myisam_sort_buffer_size = 64M
   join_buffer_size = 2M
   read_buffer_size = 2M
   sort_buffer_size = 3M
   table_cache = 1024
   thread_cache_size = 286
   interactive_timeout = 25
   wait_timeout = 1800
   connect_timeout = 10
   max_allowed_packet = 1M
   max_connect_errors = 999999
   query_cache_limit = 1M
   query_cache_size = 16M
   query_cache_type = 1
   tmp_table_size = 16M
   [mysqld_safe]
   log-error=/var/log/mysqld.log
   pid-file=/var/run/mysqld/mysqld.pid

Configure MySQL to Start at Boot
   chkconfig --level 345 mysqld on

Start the MySQL Service
   service mysqld start

Set the MySQL root Password
   mysqladmin -u root password 'mcn09demo'




                                                                             Page 12 of 19
Configuring Apache
The Apache web and log files will also reside on the EBS volume. Create the destination
directories for these files.
   mkdir -p /ebsvol/apache/www
   mkdir -p /ebsvol/apache/log

You should now create a virtual host entry for your Drupal web site. Create and edit an
apache configuration file (/etc/httpd/conf.d/mcn09.conf in this example). Replace the text
_MCN09_ with your custom values.
   NameVirtualHost *:80
   <VirtualHost *:80>
       #ServerAdmin _MCN09_
       DocumentRoot /ebsvol/apache/www
       #ServerName www._MCN09_.com
       #ServerAlias _MCN09_.com
       ErrorLog /ebsvol/apache/log/error.log
       TransferLog /ebsvol/apache/log/access.log
       <Directory /ebsvol/apache/www>
           AllowOverride All
       </Directory>
   </VirtualHost>

Configure Apache to Start at Boot
   chkconfig --level 345 httpd on

Start the Apache Service
   service httpd start

You can now visit your EC2 instance in a web browser using the public DNS name. In
this example, http://ec2-67-202-9-72.compute-1.amazonaws.com/. You will see the
Fedora test page for Apache.




                                                                            Page 13 of 19
Installing and Configuring Drupal
You will now download and extract the latest Drupal release into the Apache web server
directory on the EBS volume. You will also make the apache user the owner of all the
web files, and copy Drupal’s sample settings.
   cd /ebsvol/apache/www/
   wget http://ftp.drupal.org/files/projects/drupal-6.14.tar.gz
   tar -xzf drupal-6.14.tar.gz
   mv drupal-6.14/{*,.htaccess} ./
   rm -rf drupal-6.14*
   cp sites/default/default.settings.php sites/default/settings.php
   chown -R apache:apache .

Create the destination Drupal database. In this example, the database is called mcn09db.
   mysql -uroot -pmcn09demo -e "create database mcn09db"

Now visit your EC2 instance in a browser again and follow the typical Drupal installation
process.




                                                                           Page 14 of 19
Appendix
Configuring CRON for Drupal
Edit the crontab file for the apache user.
   crontab –u apache –e

Add the following line to the crontab replacing the URL with the name of your website.
This will cause Drupal’s cron to run at 15 and 45 minutes past each hour.
   15,45 * * * * /usr/bin/wget -O - -q http://www.yoursite.org/cron.php




                                                                          Page 15 of 19
Assigning a Static IP to Your EC2 Instance
Static IP’s in EC2 are called Elastic IP’s. You can request Elastic IP’s for free and only
pay if you do not use it.

In the EC2 Console, select Elastic IPs from the Navigation section. Click the Allocate
New Address button.




Select the new Elastic IP you allocated and then click the Associate button. Select the
EC2 instance that you would like to assign the static IP to.




That’s it. Usually within a few seconds your EC2 instance will have the new IP address
assigned. You can now configure your DNS settings to point a domain name to the IP
address.



                                                                              Page 16 of 19
Snapshotting Your EBS
As one backup measure, you should periodically snapshot your EBS volumes. You can
create new EBS volumes using these snapshots.

In a terminal, run the following commands to lock MySQL and freeze the volume’s file
system.
   mysql -uroot –pmcn09demo
   flush tables with read lock;
   system xfs_freeze -f /ebsvol

In the EC2 Console, select Volumes in the Navigation section. Select the volume that
you would like to snapshot, and then click the Create Snapshot button.




Select Snapshots in the Navigation section. You must wait for the status of your new
snapshot to say, completed. Once complete return to the terminal, unfreeze the file
system, and unlock the MySQL table.
   system xfs_freeze -u /ebsvol
   unlock tables;
   exit

Note: Your website will be unresponsive during this process.




                                                                          Page 17 of 19
Bundling Your EC2 Instance into an AMI
All this work would be lost if your instance crashed for some reason. As a way to save
your work, you can bundle your instance into a new AMI. You can then launch this AMI
as many times as you would like to have an EC2 instance that is in the exact same
configuration as when you created the AMI.

Your AWS account has X.509 certificate files available. You must copy these to your
EC2 instance in order to bundle the instance. You can find these files from the Amazon
Web Services web site, under Home Your Account Security Credentials. The file
names should be something like, cert-xxxxxx.pem and pk-xxxxxx.pem. Copy these files to
the /mnt/ directory your EC2 instance. For example, run this command on your local
machine.
   scp -i mcn09.pem cert-xxxxxx.pem pk-xxxxxx.pem 
      root@ec2-174-129-38-75.compute-1.amazonaws.com:/mnt/

You now need to run the AWS bundle command in a terminal on your EC2 instance.
   ec2-bundle-vol -e /ebsvol 
      -p mcn09-ami.img 
      -d /mnt 
      -r i386 
      -s 10240 
      -c /mnt/cert-xxxxxx.pem 
      -k /mnt/pk-xxxxxx.pem 
      -u <Your AWS User ID>

Parameters explained:
   • -e Exclude the /ebsvol from your AMI. This was saved in the EBS snapshot.
   • -p The name of the output AMI file.
   • -d The directory to output the bundled AMI.
   • -r This is a 32-bit AMI. (x86_64 for 64-bit AMI’s)
   • -s The size of the AMI in KB. (10240 == 10GB)
   • -c The path to the public X.509 cert file.
   • -k The path to the private X.509 cert file.
   • -u Your 12 digit AWS user ID/account #. Include dashes (xxxx-xxxx-xxxx).

Once the bundling process is complete, run the following command to upload your AMI
image.
   ec2-upload-bundle -m /mnt/mcn09-ami.img.manifest.xml 
      -b <Bucket Name> 
      -a <AWS Access Key> 
      -s <AWS Secret Key>

Parameters explained:
   • -m The name of the manifest file outputted from the bundle process.
   • -b The S3 bucket in which to upload the files.
   • -a Your AWS access key.
   • -s Your AWS secret key.


                                                                         Page 18 of 19
Finally you must register your AMI file. In the EC2 Console, select AMIs from the
Navigation section. Click the Register New AMI button. Enter the S3 path to your
manifest file in the form of <s3bucket>/<manifest>. For example, if you uploaded your
AMI files to a bucket, mcn09-ami-bucket, and the manifest file was named, mcn09-
ami.img.manifest.xml, you would enter, mcn09-ami-bucket/mcn09-ami.img.manifest.xml.




You should now see this new AMI in the list of available AMI’s that you can launch.




                                                                          Page 19 of 19

More Related Content

PDF
AWS essentials EC2
PDF
AWS essentials S3
PDF
Amazon AWS Identity Access Management
PDF
Connect Amazon EC2 Linux Instance
PDF
User guide
DOCX
How to configure amazon ec2 load balancer
DOCX
Build your own secure mail server on the cloud using Amazon Web Services
PDF
Magento Hosting on AWS
AWS essentials EC2
AWS essentials S3
Amazon AWS Identity Access Management
Connect Amazon EC2 Linux Instance
User guide
How to configure amazon ec2 load balancer
Build your own secure mail server on the cloud using Amazon Web Services
Magento Hosting on AWS

What's hot (15)

DOCX
How to Configure Amazon AWS EC2 Elastic IP Address
DOCX
Network Manual
PDF
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
PDF
How To Create EBS Snapshot and Restore EBS Snapshot – Linux Instance
PPTX
Configuration Management and Provisioning Are Different
PDF
How To Install and Configure AWS CLI for Windows
PDF
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
PPTX
Aws overview part 2(compute services)
PPT
Apache installation and configurations
DOCX
Azure File Share and File Sync guide (Beginners Edition)
PPTX
Benchmarking top IaaS providers - A practical study
PPTX
Benchmarking top IaaS providers - A practical study
ODT
Streaming twitter data using kafka
PDF
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
PDF
Detect and fix the azure sql resources which uses tls version less than 1.2
How to Configure Amazon AWS EC2 Elastic IP Address
Network Manual
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create EBS Snapshot and Restore EBS Snapshot – Linux Instance
Configuration Management and Provisioning Are Different
How To Install and Configure AWS CLI for Windows
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
Aws overview part 2(compute services)
Apache installation and configurations
Azure File Share and File Sync guide (Beginners Edition)
Benchmarking top IaaS providers - A practical study
Benchmarking top IaaS providers - A practical study
Streaming twitter data using kafka
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Detect and fix the azure sql resources which uses tls version less than 1.2
Ad

Viewers also liked (18)

PDF
Calculating the Savings of Moving Your Drupal Site to the Cloud
PPTX
8 Web Practices for Drupal
PDF
Moving In: how to port your content from * to Drupal
PDF
Recipes for Drupal distributions
PDF
Migrate
PDF
Staging Drupal 8 31 09 1 3
PPTX
Drupal Migration
PPT
Create Website In Indian Languages using drupal
PDF
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
PPTX
Building Archivable Websites
PDF
Using Drupal Features in B-Translator
PDF
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
PDF
Drupal in the Cloud with Windows Azure
PPTX
Data migration to Drupal using the migrate module
PPT
Migraine Drupal - syncing your staging and live sites
ODP
Content Staging in Drupal 8
PDF
Managing Translation Workflows in Drupal 7
PPTX
Migration from Legacy CMS to Drupal
Calculating the Savings of Moving Your Drupal Site to the Cloud
8 Web Practices for Drupal
Moving In: how to port your content from * to Drupal
Recipes for Drupal distributions
Migrate
Staging Drupal 8 31 09 1 3
Drupal Migration
Create Website In Indian Languages using drupal
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Building Archivable Websites
Using Drupal Features in B-Translator
GeorgiaGov's move to Drupal - presentation by Nikhil Deshpande @nikofthehill
Drupal in the Cloud with Windows Azure
Data migration to Drupal using the migrate module
Migraine Drupal - syncing your staging and live sites
Content Staging in Drupal 8
Managing Translation Workflows in Drupal 7
Migration from Legacy CMS to Drupal
Ad

Similar to Moving Drupal to the Cloud (20)

DOCX
docker.docx
PDF
Sun_AmazonEC2_GettingStartedGuide
PPTX
Presentation-1.pptx
PPTX
Presentation.pptx
PPTX
Presentation.pptx
PDF
Rstudio in aws 16 9
PPTX
Creating and managing amazon ec2 instances(linux)
PPTX
AWS_EC2_Instance_Bharathiyaruniversity.pptx
PDF
Amazon cloud intance launch
PDF
Amazon cloud intance launch3
PDF
Amazon cloud intance launch3
PPTX
Amazon cloudtutorial
PPT
sfdx continuous Integration with Jenkins on aws (Part I)
PDF
Activity 9 Working with AWS CloudTrail.pdf
PPTX
PDF
Installing WordPress on AWS
PDF
Aws project jenkins-build-server
PDF
ArcMC for AWS 2.2 P1 Setup Guide
PDF
AWS System Administration Best Practices for Sysadmins in the Amazon Cloud 1s...
PDF
How To Create EC2 instance Linux Server
docker.docx
Sun_AmazonEC2_GettingStartedGuide
Presentation-1.pptx
Presentation.pptx
Presentation.pptx
Rstudio in aws 16 9
Creating and managing amazon ec2 instances(linux)
AWS_EC2_Instance_Bharathiyaruniversity.pptx
Amazon cloud intance launch
Amazon cloud intance launch3
Amazon cloud intance launch3
Amazon cloudtutorial
sfdx continuous Integration with Jenkins on aws (Part I)
Activity 9 Working with AWS CloudTrail.pdf
Installing WordPress on AWS
Aws project jenkins-build-server
ArcMC for AWS 2.2 P1 Setup Guide
AWS System Administration Best Practices for Sysadmins in the Amazon Cloud 1s...
How To Create EC2 instance Linux Server

More from Ari Davidow (12)

PPTX
2016 12-21 rules for radical project managers
PPT
Limmudboston2016 hebrewtypography-02
PPT
Limmudboston2016 hebrewtypography-01
PPTX
Making the Transition to Agile: what we did, what worked, and what we learned
PPTX
A small archive in the clouds
PPT
Jewish music online
PPT
Mashing Up History and Teaching Our Kids: The Public Is Invited
PPT
Project Management for the resource-challenged
PPT
Hebrew Typography1
PPT
Hebrew Typography2
PPT
JWA-RP
PDF
Project Management on one foot
2016 12-21 rules for radical project managers
Limmudboston2016 hebrewtypography-02
Limmudboston2016 hebrewtypography-01
Making the Transition to Agile: what we did, what worked, and what we learned
A small archive in the clouds
Jewish music online
Mashing Up History and Teaching Our Kids: The Public Is Invited
Project Management for the resource-challenged
Hebrew Typography1
Hebrew Typography2
JWA-RP
Project Management on one foot

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
A Presentation on Artificial Intelligence
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
KodekX | Application Modernization Development
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
A Presentation on Artificial Intelligence
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Monthly Chronicles - July 2025
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
KodekX | Application Modernization Development
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Moving Drupal to the Cloud

  • 1. Moving Drupal to the Cloud: A step-by-step guide and reference document for hosting a Drupal web site on Amazon Web Services MCN 2009: Cloud Computing Primer Workshop Charles Moad <cmoad@imamuseum.org> Robert Stein <rstein@imamuseum.org> Ari Davidow <adavidow@jwa.org> INTRODUCTION ........................................................................................................................................ 2 CONVENTIONS USED IN THIS DOCUMENT ................................................................................................... 2 EC2 CONSOLE ............................................................................................................................................ 3 PREREQUISITES TO LAUNCHING AN EC2 INSTANCE .................................................................. 4 CREATING A KEY PAIR ............................................................................................................................... 4 CREATING A SECURITY GROUP .................................................................................................................. 5 SELECTING A STARTER AMI ...................................................................................................................... 6 LAUNCHING AND CONNECTING TO YOUR EC2 INSTANCE........................................................ 7 STARTING YOUR EC2 INSTANCE ................................................................................................................ 7 CONNECTING TO YOUR EC2 INSTANCE ...................................................................................................... 8 Preparing Your SSH Key Pair for Putty ............................................................................................... 8 CONFIGURING YOUR EC2 INSTANCE ................................................................................................ 9 INSTALLING PREREQUISITES ....................................................................................................................... 9 CREATING AN EBS VOLUME .................................................................................................................... 10 ATTACHING YOUR EBS VOLUME............................................................................................................. 11 FORMATTING AND MOUNTING YOUR EBS VOLUME ................................................................................ 11 CONFIGURING MYSQL............................................................................................................................. 12 CONFIGURING APACHE............................................................................................................................. 13 INSTALLING AND CONFIGURING DRUPAL.................................................................................... 14 APPENDIX ................................................................................................................................................. 15 CONFIGURING CRON FOR DRUPAL .......................................................................................................... 15 ASSIGNING A STATIC IP TO YOUR EC2 INSTANCE.................................................................................... 16 SNAPSHOTTING YOUR EBS ...................................................................................................................... 17 BUNDLING YOUR EC2 INSTANCE INTO AN AMI....................................................................................... 18 Page 1 of 19
  • 2. Introduction This document aims to give attendees a step-by-step guide on how to host a Drupal website using the Amazon Web Services. It should also serve as a valuable reference document. The Drupal instance will be hosted on a LAMP stack and steps will be shown on how to backup and snapshot your EC2 instance. Conventions Used in this Document • Normal text • Filename or itemname • Command line Page 2 of 19
  • 3. EC2 Console This guide uses the EC2 Console, a web interface provided by Amazon which allows complete control of running and managing EC2 instances in the cloud. Page 3 of 19
  • 4. Prerequisites to Launching an EC2 Instance Creating a Key Pair You must specify a security key pair to use when launching EC2 instances. A key pair is actually used as your SSH key pair for connecting to your instance. There is no password access. You can technically launch an instance without a key pair, but then you would have no means to log into the running instance. In the EC2 console, select Key Pairs from the Navigation section. Click the Create Key Pair button to create a new key pair. In this example we will name our key pair, mcn09. Once you create your key pair, your browser will download the actual private key file. In this example the file will be named, mcn09.pem. Keep this file secure. Page 4 of 19
  • 5. Creating a Security Group Think of security groups simply as your firewall rules for EC2 instances. You use it to say which ports are open, and who they are open to. You must specify a security group when launching an EC2 instance. At a minimum, you will want to allow access on port 22 so you can SSH and port 80 to serve web pages. In the EC2 console, select Security Groups from the Navigation section. Click the Create Security Group button to create a new group. In this example we will name our security group, mcn09. Optionally enter a description for the group. Configure the ports as shown in the image below. Fill in each line and click Save. The Source item should be set to 0.0.0.0/0 to allow access to allow machines. Reference CIDR Notation to learn more about this setting or click the Help button seen in the interface below. Page 5 of 19
  • 6. Selecting a Starter AMI You’ll need to select an Amazon Machine Image to use as a basis for your EC2 instance. There exists AMI’s preconfigured with Drupal. This guide however will use a stock, Amazon provided Fedora 32-bit AMI. Specifically we are using, ami-48aa4921, as shown below. EC2 has a variety of instance sizes that you can launch your AMI’s on. They vary in storage, memory, priority, processing power, and most namely, price. m1.small and c1.medium instance sizes are 32-bit and can only run 32-bit AMI’s. All remaining instance sizes are 64-bit. Several studies have shown that the c1.medium instance size is by far the best bang for your buck. It is strongly recommended that you use this size for moderate traffic LAMP web sites. Page 6 of 19
  • 7. Launching and Connecting to Your EC2 Instance Starting Your EC2 Instance You are now ready to launch your EC2 instance. After selecting the AMI (ami- 48aa4921), click the Launch button. Fill in the form as shown in the image below. Most importantly, select the mcn09 key pair and mcn09 security group that you have already configured. In this example, we are launching a single m1.small instance. In the EC2 console, click the Instances link in the Navigation section. Here you can monitor the progress of your instance. Proceed once the status says, running. In this example, our launched instance has the identifier, i-58d96330. Page 7 of 19
  • 8. Connecting to Your EC2 instance First you must get the public DNS name assigned to your new instance. You can find this in the instance details of the EC2 Console. In this example, our public DNS is ec2- 67-202-9-72.compute-1.amazonaws.com. If you are on a Linux or OSX machine, you can now SSH to your machine using the following command in a terminal. If you are using Windows, follow the instructions for preparing your SSH key pair for Putty. ssh –i mcn09.pem root@ ec2-67-202-9-72.compute-1.amazonaws.com Preparing Your SSH Key Pair for Putty If you are using Windows, you must first convert your key pair file to work with Putty. If you are on a Linux or OSX machine, simply skip this section. From the Start Menu, launch the PuTTYgen program under the PuTTY menu item. Select Load private key from the File menu. Navigate and select the private key pair file you downloaded earlier. In this example, the file name was mcn09.pem. Select Save private key from the File menu. In this example, we name the new file mcn09.ppk. Now you can connect to your running EC2 instance from Putty by providing this key pair file under Connection SSH Auth. Use the username, root. Page 8 of 19
  • 9. Configuring Your EC2 Instance Installing Prerequisites The AMI you started with have next to nothing installed. You must now install the traditional LAMP stack as well as a few additional tools for Drupal. Now you should run the following two commands to install our LAMP stack and some other useful tools. yum groupinstall "MySQL Database" "Web Server" yum install php-gd xfsprogs phpMyAdmin This will install Apache and MySQL as well as the library php-gd to make Drupal happy. phpMyAdmin is an extremely useful web interface for administering MySQL. Additionally we install xfsprogs so we can manipulate XFS file systems. All web and database files will be hosted on an Elastic Block Store (EBS) volume that you will attach to your running instance. The XFS file system is an ideal format for this volume since it can be resized in case you need more space later, and it can be frozen which prevents corrupt database files when snapshotting the volume. This will be discussed later in the document. Page 9 of 19
  • 10. Creating an EBS Volume Storage on EC2 instances is considered ephemeral, meaning that it goes away when your EC2 instance goes away. If for some reason your instance crashed, you would lose all of your web and database files. To solve this problem, Amazon offers virtual block devices you can attach to your running EC2 instances. Elastic Block Store (EBS) volumes can range from 1GB to 1TB in size. These volumes are separate from your instance. They remain persistent if your instance is terminated. You can detach an EBS volume from one instance and attach it to another. Also, you can attach multiple EBS volumes to one instance and even setup RAID configurations amongst those volumes. You must first note which availability zone your instance is running in. EBS volumes can only be attached to instances running in the same zone. You can find this in the instance details of the EC2 Console. In this example, our instance is running in zone us- east-1a. In the EC2 Console, click on Volumes in the Navigation section. Click the Create Volume button to start the creation process. Make the EBS volume a reasonable size and in the same zone as your EC2 instance. Leave Snapshot set to No Snapshot. Page 10 of 19
  • 11. Attaching Your EBS Volume Once the EBS volume is finished creating you will attach it to your running EC2 instance. In the EC2 Console, make sure you are still in the Volumes section. Click the newly created EBS volume (vol-f5c6399c in this example) then click the Attach Volume button. Select the EC2 instance you just launched and the device location you want the volume to be mounted. In this example, we select our instance, i-58d96330, and the default device location, /dev/sdf. Formatting and Mounting Your EBS Volume You will now need to format and mount your EBS volume on your EC2 instance. In this example, you are mounting the volume at /ebsvol. We will also add an entry to /etc/fstab so the volume will be automatically mounted in the event of a reboot. Run the following commands in a terminal connected to your instance. mkdir /ebsvol mkfs.xfs /dev/sdf echo "/dev/sdf /ebsvol xfs noatime 0 0" >> /etc/fstab mount /ebsvol/ Page 11 of 19
  • 12. Configuring MySQL The MySQL database and log files will reside on the EBS volume. You must now configure MySQL to know where to host these files. First, create the destination directories on the EBS volume. mkdir -p /ebsvol/mysql/lib/mysql mkdir -p /ebsvol/mysql/log/mysql Edit the file, /etc/my.cnf, to contain the following. [mysqld] #datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 innodb_file_per_table datadir = /ebsvol/mysql/lib/mysql #log_slow_queries = /ebsvol/mysql/log/mysql/mysql-slow.log #long_query_time = 10 max_connections = 250 max_user_connections = 250 key_buffer = 36M myisam_sort_buffer_size = 64M join_buffer_size = 2M read_buffer_size = 2M sort_buffer_size = 3M table_cache = 1024 thread_cache_size = 286 interactive_timeout = 25 wait_timeout = 1800 connect_timeout = 10 max_allowed_packet = 1M max_connect_errors = 999999 query_cache_limit = 1M query_cache_size = 16M query_cache_type = 1 tmp_table_size = 16M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Configure MySQL to Start at Boot chkconfig --level 345 mysqld on Start the MySQL Service service mysqld start Set the MySQL root Password mysqladmin -u root password 'mcn09demo' Page 12 of 19
  • 13. Configuring Apache The Apache web and log files will also reside on the EBS volume. Create the destination directories for these files. mkdir -p /ebsvol/apache/www mkdir -p /ebsvol/apache/log You should now create a virtual host entry for your Drupal web site. Create and edit an apache configuration file (/etc/httpd/conf.d/mcn09.conf in this example). Replace the text _MCN09_ with your custom values. NameVirtualHost *:80 <VirtualHost *:80> #ServerAdmin _MCN09_ DocumentRoot /ebsvol/apache/www #ServerName www._MCN09_.com #ServerAlias _MCN09_.com ErrorLog /ebsvol/apache/log/error.log TransferLog /ebsvol/apache/log/access.log <Directory /ebsvol/apache/www> AllowOverride All </Directory> </VirtualHost> Configure Apache to Start at Boot chkconfig --level 345 httpd on Start the Apache Service service httpd start You can now visit your EC2 instance in a web browser using the public DNS name. In this example, http://ec2-67-202-9-72.compute-1.amazonaws.com/. You will see the Fedora test page for Apache. Page 13 of 19
  • 14. Installing and Configuring Drupal You will now download and extract the latest Drupal release into the Apache web server directory on the EBS volume. You will also make the apache user the owner of all the web files, and copy Drupal’s sample settings. cd /ebsvol/apache/www/ wget http://ftp.drupal.org/files/projects/drupal-6.14.tar.gz tar -xzf drupal-6.14.tar.gz mv drupal-6.14/{*,.htaccess} ./ rm -rf drupal-6.14* cp sites/default/default.settings.php sites/default/settings.php chown -R apache:apache . Create the destination Drupal database. In this example, the database is called mcn09db. mysql -uroot -pmcn09demo -e "create database mcn09db" Now visit your EC2 instance in a browser again and follow the typical Drupal installation process. Page 14 of 19
  • 15. Appendix Configuring CRON for Drupal Edit the crontab file for the apache user. crontab –u apache –e Add the following line to the crontab replacing the URL with the name of your website. This will cause Drupal’s cron to run at 15 and 45 minutes past each hour. 15,45 * * * * /usr/bin/wget -O - -q http://www.yoursite.org/cron.php Page 15 of 19
  • 16. Assigning a Static IP to Your EC2 Instance Static IP’s in EC2 are called Elastic IP’s. You can request Elastic IP’s for free and only pay if you do not use it. In the EC2 Console, select Elastic IPs from the Navigation section. Click the Allocate New Address button. Select the new Elastic IP you allocated and then click the Associate button. Select the EC2 instance that you would like to assign the static IP to. That’s it. Usually within a few seconds your EC2 instance will have the new IP address assigned. You can now configure your DNS settings to point a domain name to the IP address. Page 16 of 19
  • 17. Snapshotting Your EBS As one backup measure, you should periodically snapshot your EBS volumes. You can create new EBS volumes using these snapshots. In a terminal, run the following commands to lock MySQL and freeze the volume’s file system. mysql -uroot –pmcn09demo flush tables with read lock; system xfs_freeze -f /ebsvol In the EC2 Console, select Volumes in the Navigation section. Select the volume that you would like to snapshot, and then click the Create Snapshot button. Select Snapshots in the Navigation section. You must wait for the status of your new snapshot to say, completed. Once complete return to the terminal, unfreeze the file system, and unlock the MySQL table. system xfs_freeze -u /ebsvol unlock tables; exit Note: Your website will be unresponsive during this process. Page 17 of 19
  • 18. Bundling Your EC2 Instance into an AMI All this work would be lost if your instance crashed for some reason. As a way to save your work, you can bundle your instance into a new AMI. You can then launch this AMI as many times as you would like to have an EC2 instance that is in the exact same configuration as when you created the AMI. Your AWS account has X.509 certificate files available. You must copy these to your EC2 instance in order to bundle the instance. You can find these files from the Amazon Web Services web site, under Home Your Account Security Credentials. The file names should be something like, cert-xxxxxx.pem and pk-xxxxxx.pem. Copy these files to the /mnt/ directory your EC2 instance. For example, run this command on your local machine. scp -i mcn09.pem cert-xxxxxx.pem pk-xxxxxx.pem root@ec2-174-129-38-75.compute-1.amazonaws.com:/mnt/ You now need to run the AWS bundle command in a terminal on your EC2 instance. ec2-bundle-vol -e /ebsvol -p mcn09-ami.img -d /mnt -r i386 -s 10240 -c /mnt/cert-xxxxxx.pem -k /mnt/pk-xxxxxx.pem -u <Your AWS User ID> Parameters explained: • -e Exclude the /ebsvol from your AMI. This was saved in the EBS snapshot. • -p The name of the output AMI file. • -d The directory to output the bundled AMI. • -r This is a 32-bit AMI. (x86_64 for 64-bit AMI’s) • -s The size of the AMI in KB. (10240 == 10GB) • -c The path to the public X.509 cert file. • -k The path to the private X.509 cert file. • -u Your 12 digit AWS user ID/account #. Include dashes (xxxx-xxxx-xxxx). Once the bundling process is complete, run the following command to upload your AMI image. ec2-upload-bundle -m /mnt/mcn09-ami.img.manifest.xml -b <Bucket Name> -a <AWS Access Key> -s <AWS Secret Key> Parameters explained: • -m The name of the manifest file outputted from the bundle process. • -b The S3 bucket in which to upload the files. • -a Your AWS access key. • -s Your AWS secret key. Page 18 of 19
  • 19. Finally you must register your AMI file. In the EC2 Console, select AMIs from the Navigation section. Click the Register New AMI button. Enter the S3 path to your manifest file in the form of <s3bucket>/<manifest>. For example, if you uploaded your AMI files to a bucket, mcn09-ami-bucket, and the manifest file was named, mcn09- ami.img.manifest.xml, you would enter, mcn09-ami-bucket/mcn09-ami.img.manifest.xml. You should now see this new AMI in the list of available AMI’s that you can launch. Page 19 of 19