You are here

sandbox

Using Amazon EC2 micro instances to create development sandboxes for Drupal

I recently contracted out some work for a project I am working on in Drupal because it involved CSS, HTML and theming and quite frankly, my skills in that area suck. I used ODesk because I do some other data entry outsourcing there and it works quite well. Anyways, it was relatively easy to find a qualified person to do the work. Now the supposedly hard part, setting up a sandbox for a remote worker to access and do the work. This was a rush job that needed to get done yesterday so I needed something setup quickly.

Well luckily with Amazon EC2 and its nifty cloud, this turned out to be quite easy. I created a a micro instance in the US East (Virginia) region which costs a whopping 2 cents per hour (works out to about $15 / month). This can be decreased significantly by purchasing reserved instances. I used an EBS-backed instance so that I can start / stop it at will and not have it running if I don't need. I also assign a custom security group to it so I can add or drop custom firewall rules and it doesn't affect my other live instances. Finally, I use Ubuntu 10.04 LTS and Alestic's AMIs because its fast and simple to setup and run.

So now I have a running Ubuntu instance, now what? Well with a few simple commands, I can get a Drupal website up and running. Keep in mind this is a short term server that I need to focus on ease of use, not security so what I am doing would not be appropriate for anything else.

Copy authorized keys to root .ssh dir so I can login as root:
sudo cp ~/.ssh/authorized_keys /root/.ssh/

Now logout and SSH back in as root.

Update your Ubuntu instance:
apt-get update && apt-get -y upgrade

Install LAMP server:
tasksel install lamp-server

Edit your default site Apache configuration file with your favourite editor and point to your new htdocs dir (/home/htdocs):
pico /etc/apache2/sites-available/default

Enable mod rewrite for Drupal and reload Apache:
a2enmod rewrite
/etc/init.d/apache2 reload

Login to MySQL and create your database:
mysql -p
create database databasename

Now ssh to your live/development server and create a backup of your site with db to move to sandbox:
cd /home/htdocs
mysqldump -p databasename > db_date.sql
cd ..
tar .zcvf mywebsite.tar.gz htdocs/
rm htdocs/db_date.sql
scp mywebsite.tar.gz sandbox:/home/htdocs/

Now flip back to your sandbox and extract your tar file:

tar xfz mysqwebsite.tar.gz

Edit your Drupal settings file to point to database:

pico sites/default/settings.php

Load your database from the dump and delete the dump file:

mysql -p databasename < /home/htdocs/db_date.sql
rm /home/htdocs/db_date.sql

Now your website should be operational.

For quick access to your remote developer you can simply enable password security for your SSH daemon by changing PasswordAuthentication setting to Yes, assign a password for root and reloading SSH daemon:

pico /etc/ssh/sshd_config
passwd
/etc/init.d/sshd reload

Because most FTP clients support SFTP (FTP over SSH), your remote developer can now access your sandbox and you should be good to go.

Keep in mind that giving out root access is not ideal, nor is most of what I have talked about here good for security. In fact, it flies in the face of most best practice security measures that should be taken for any server. But if you need to get a server up and running fast for a remote worker to get stuff done quickly, it works and does the job.

Make sure you stop and/or terminate your instance as soon as you are done with it! Enjoy.