You are here

web development

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.

Caching trick when doing web development with Chrome

So the Chromium browser really loves to cache, its one of the reasons why its so fast. In fact, not even the usual holding of the SHIFT key and pressing refresh will bypass its caching, at least not using the latest version (7.0.517.41) under Ubuntu.

One workaround is to go into your preferences, click the "Under the hood" tab, click the "Clear browsing data", select "Empty the cache" checkbox, then click the "Clear browsing data" button. Wow, thats a lot of steps and when you're developing, this is a real pain in the ass.

There is another solution though. You can pass startup options to Chrome and set the cache to zero, that way the cache is never used. This is perfect for development because really, how often have you been screwed and sent on wild goose chases because of browser cache meanwhile you were trying to figure out why your changes didn't fix the problem?

So create another shortcut to Chrome and call this one Dev Chrome, or something uniquely identifiable. Edit the properties, specifically the startup options (called Command in Ubuntu) and add a parameter at the end that says:

--disk-cache-size=0

So the entire line should look something like:

/usr/bin/chromium-browser %U --disk-cache-size=0

Now when you do web development, launch and use your dev version of Chrome instead of your regular version. Voila!