(Some familiarity with Amazon AWS is assumed.)
I have always wanted to setup a high performance Drupal on an AWS EC2. There are several advantages of running your website (or web application) on the AWS. Amazon EC2 creates and provisions virtual Linux (or Windows) servers for you and charge you an hourly rate for usage.
With AWS, it becomes easy to distribute and share the Drupal image with others. And of course it is much easier to scale and is definitely cheaper. You can have different virtual servers running the search engine, database and application servers, therefore all scaling independently of each other.
With the introduction of Micro instances and better yet, free micro instances, the barrier to entry for a new user has really dropped.
I assume you have or can create an Amazon AWS account and use their management console. These aspects are very well covered in Amazon's site and I will not get into the details of creating an account, etc. Amazon has done a great job of creating the documentation and tutorials for getting started.
I will show how to:
1. Setup a LAMP stack on Ubuntu
2. Setup Drupal on the LAMP stack
3. How to install phpmyadmin
4. Configure the database to reside in the EBS instead of the ephemeral instance storage.
1. Setup a LAMP stack on Ubuntu:
I used a 64 bit image Ubuntu image for my purpose. Amazon provides both 32 bit and 64 bit micro instances, but I wanted to start with 64 bit, because their larger servers are only 64 bit and I can use the same image to scale up to larger Amazon servers. I used the Ubuntu image as my base image. This image is available in the US west region only. (Images are unique to regions and you can get similar images for the region you want to use).
Once your AWS account is setup, sign into the Amazon AWS console. Click on the EC2 tab. Check the region you are running in. If you want to run in US West, select it and click on launch instance. The popup following that will allow you to select an image. Search the image id: ami-01772744. Click on start and continue with default options. You will have to select a key-pair and security group. Make sure the port 80 and port 22 are open in the security group you want to use. Port 80 will allow the HTTP access and port 22 will allow the ssh connectivity to the server.
You also have to know the location of the Amazon's private key file (.pem) for the key-value pair. The Ubuntu server takes a few minutes to start and be available.
From the command line on your local machine type:
The part following ubuntu@ has to be replaced by your server's public dns name that Amazon provides on the console. Note there is no root user and all commands will work through sudo. Ubuntu does this to avoid any root user logins. You can access all the administrative functionality using sudo.
BTW, if the command above does not read and execute due to permission problem, you might want to first run:
chmod 600 [path to key file]/[key file name].pem
Once connected to the remote server console (your first big milestone BTW), you can create a password for the ubuntu user by typing in (optional):
sudo passwd ubuntu
If you want to enable SSH access via passwords so you don't require the .pem file every time you can do the following:
edit /etc/ssh/sshd_config to have
Restart the ssh deamon
sudo service ssh restart
sudo /etc/init.d/apache2 restart
Now with the basic logistics in place, let's set up the LAMP stack on this Ubuntu instance. I found this to be simpler than what I had expected. Write down any usernames and passwords you create from this point on
sudo tasksel install lamp-server
Drupal will need the re-write functionality to be able to perform clean URLs, so run the command
sudo a2enmod rewrite
That's it. You lamp stack is setup.
Go to http://[your public dns] and you should see some output form Apache.
BTW, what I also find really useful is to create some short cuts in the .profile file. For example instead of typing ls -al I can then type la and since I make spelling mistakes while typing sudo, I can point sodu to sudo as well. To do this, edit the /home/ubuntu/.profile file
sudo vim /home/ubuntu/.profile
Add the line:
alias la='ls -al'
2. Setup Drupal on the LAMP stack
Setting up Drupal on the LAMP stack is usually just 1 line command and we will need to perform some basic operations:
sudo apt-get install drupal6
edit the file /etc/apache2/sites-enabled/000-default and change the make the change so that DocumentRoot is now as follows:
You can install Drupal anywhere and just point the DocumentRoot to that location. Also comment our the block that starts with
Also edit the file /etc/apache2/conf.d/drupal6.conf and comment out the line
Alias /drupal6 /usr/share/drupal6
restart the Apache so the above configuration changes are reflected correctly
sudo service apache2 restart
Now go to http://[your public dns/install.php] and voila you are in business.
3. Setup phpmyadmin:
To access the database through phpmyadmin, you will need to install the phpmyadmin and access the URL of the application. Again, this is only optional and you can access all the SQL functionality form command line also. Installing phpmyadmin is trivial:
sudo apt-get install phpmyadmin
And you are done. Follow the install options if any.
Go the the phpmyadmin application via:
http://[your public dns/phpmyadmin]
The user name is usually root.
4. Configure the database to reside in the EBS instead of the ephemeral instance storage:
Amazon's instances are ephemeral and the storage on the instance is ephemeral as well. That is if the instance is shutdown, the data on it will go away. Now that is not a very desirable configuration. However, Amazon allows you to mount persistant storage on top of the instance. You can mount any number of 1 TB drives on the instance. You can chose the size of the mounted drive at instance startup time.
Essentially, there will already be a mounted drive which you can find by typing:
The on the mounted drive you can create corresponding directories for logs, DB files and lib
You link the directories on the the mounted drive to the directories on your instance. The set of commands are as follows:
Shut down the SQL first:
sudo /etc/init.d/mysql stop
And then create the folders and link them:
sudo mkdir /vol/etc /vol/lib /vol/log
sudo mv /etc/mysql /vol/etc/
sudo mv /var/lib/mysql /vol/lib/
sudo mv /var/log/mysql /vol/log/
sudo mkdir /etc/mysql
sudo mkdir /var/lib/mysql
sudo mkdir /var/log/mysql
echo "/vol/etc/mysql /etc/mysql none bind" | sudo tee -a /etc/fstab
sudo mount /etc/mysql
echo "/vol/lib/mysql /var/lib/mysql none bind" | sudo tee -a /etc/fstab
sudo mount /var/lib/mysql
echo "/vol/log/mysql /var/log/mysql none bind" | sudo tee -a /etc/fstab
sudo mount /var/log/mysql
sudo /etc/init.d/mysql start
So, in summary, we saw how to setup the LAMP server, install Drupal and make sure the DB runs on the persistant storage. There is still work to harden the image and to create the image from the instance, and that will be covered in a subsequent blog.