WordPress and AWS : Run your blog in 5 minutes on Amazon


Today we will see how to install WordPress using Amazon CloudFormation option of amazon web service (aws). Amazon CloudFormation will create all necessary resources for running WordPress on AWS. Not only it will create necessary resources it will also take care of managing, updating and provisioning resources in  a predictable fashion. It relives developers and system administrators from creating and managing resource. To use Amazon CloudFormation follow following steps :
Open Amazon Management Console and select CloudFormation as shown below
a2-1_awsmanagementconsole

In CloudFormation, Select Create Stack which will give two options :

  1. Design Template
  2. Create New Stack

Select Create New Stack.

a2-2_aws_createstack
Create New Stack will start the wizard for creating new stack and will expect some inputs. First option is to select template option, which presents with option of Design a template or to select existing or saved template from local file or use Amazon s3 template. Amazon provides many sample solution templates.  We will use word press single instance template, Click on view link as shown below
a2-3_aws_templatepath
Copy the link from address bar which will be like
https://s3-us-west-1.amazonaws.com/cloudformation-templates-us-west-1/WordPress_Single_Instance.template and click on next.
aws-template-worpress
Next we need to provide stack details like stack name, database, username, password etc… and click next.
a2-4_stackdetails
Provide tag name and value and click next.
a2-5_keydetail
Review all details and click on create.a2-6_reviewstack
It will create Amazon EC2 Instance automatically for this.
We can see stack creating in progressa2-7_aws_stackcreationinprogressstatus
We can see it will create necessary security groups, EC2 instance for us, finally we can see status as CREATE_COMPLETE.a2-8_aws_stackcomplete
Click on output tab below and open the url in new tab.
a2-9_aws_urlofwordpress
Voila! It will open the browser new window with word press installation wizard.
a2-10_aws_wordpressinstallation

Fill necessary information and click on Install WordPress button at end. Installation will finish in seconds and we will be presented with admin login page.
a2-11_aws_wordpress_login

We can remove login and see home page of the blog.

a2-12_aws_wordpress_home

Before posting we need create the S3 bucket for storing the data about the blog post. Again create a stack with Amazon s3 bucket template.  It will create a s3 bucket
a2-15_aws_newstack_bucket

Once the stack creation is complete, check for the Ec2 instance created.

a2-17_aws_management_console
Connect EC2 instance using ssh. Once connected install git using
sudo yum -i install git
Clone the wp-static repository from github using following command.
git clone git://github.com/eistrati/WP-static.git $HOME/WP-static
Modify the httpd.conf file to allow permlinks to overide run following commands
sudo sed -i .bak -e ‘s/AllowOverride None /AllowOverride All/g’ /etc/httpd/conf/httpd.conf
Restart the service by issuing following command
sudo service httpd restart
Execute
sudo cp $HOME/WP-static/wpstatic.sh /var/www/html/wordpress/;
cd /var/www/html/wordpress
sudo /bin/sh wstatic.sh
sudo chown -R apache:apache /var/www/html/wordpress
Lets attach bucket for static hosting.
Open Services from Management Console and select s3, it will display all buckets from list select the bucket we created earlier
a2-19_aws_buckets

Select the bucket and click on Properties which will display all properties

a2-21_aws_allproperties

Select Static web hosting

a2-22_aws_enablewebhosting

Set parameters as shown and copy the endpoint shown above. Open the ssh windows and execute following commands

aws configure

Enter keys details asked, specify the region. It will create the configuration file in Home directory. Now lets push all the contents to Amazon s3 by excecuting the following commands.

cd /var/www/html/wordpress
aws s2 cp –recursive –acl public-read wordpress-static s3://<bucket name from above figure>>/wordpress

We can create a cron job to push content every minute to bucket.

Go back to web and login in admin, which will bring up dashboard and now we can create new post.

a2-23_aws_wordpressadmindashboard
We are done with setting and running WordPress on AWS.

Leave a comment

Your email address will not be published. Required fields are marked *