4 Apr 2011

Word Up - An Amazon EC2 LAMP for Wordpress

AWS EC2 is a virtual server platform hosted in the Amazon cloud which you manage yourself. It offers builds around MS Server 2003 to 2008 as well as varying flavours of Linux and is priced intelligently on a “per use” basis. You can choose the server location and either build your own for upload or choose from one of the many pre-configured Amazon Machine Images (AMI’s). 
In this post I’ll provide an overview of instances and run through a base Wordpress installation to an Ubuntu LAMP.

Procedure :
  • Build a quick and open Amazon EC2 Ubuntu LAMP server. 
  • With a fixed IP. 
  • Offering SFTP access. 
  • Running a base installation of WordPress. 
Prerequisites :
Timeframe :
  • Estimated 30 minutes. 
Instance Overview :
  • An Instance Store machine – This a dynamic build, you can modify it whilst it’s up but once terminated all changes are lost. 
  • An EBS build – Has its full system volume held in Amazons Elastic Block Storage area, this facilitates instance stop & start plus options for re-bundling a modified system into your own custom AMI.
    Using EBS you pay for backed storage use with costs presently at $0.10 per GB month (Equating to +$1 per year for a 10GB EBS volume on top of the reservation cost) with all data I/O also chargeable at $0.10 per 1 million requests to the volume. Although these add-ons do boost reserved instance costs they don’t add much to them, and for me it’s still an attractive and competitively priced solution for what is in effect a fully accessible Virtual Private Server offering not only all the related flexibility you would expect from such a device, but with the accompanying bonuses of AWS Elastic Computing – i.e Image snapshotting and re-bundling, server stop/start & reboot, plus easy security and directly scaleable paths into multi-server load balancing and auto-scaling.

    Ubuntu’s EBS AMI’s are all 15GB so should you wish to take advantage Amazons free 10GB Micro-Linux tier instance number ami-c2a255ab is a 10GB Lucid build (although it’s only available in US East Zone 1).

    Build :
    Chose your instance type and fire it up, choosing your size option and selecting (or creating) a relevant security group & key pair. Copy the keypair (.pem) file to your local system and edit your security group to allow access for the following ports..
    • Port 80 – Web Server 
    • Port 22 – For SSH/SFTP access 
    Port 80 requires open IP access ( as it’s the web server, port 22 you can set as per your security preferences, although I personally like to nail it down to my own IP(s). 

    Once running, open Elastic IP’s from the AWS console, allocate an IP and associate it with your running instance. This is now your server IP address and will remain so after any stop/starts, it’s linked with your top level AWS account not the instance which allows you to re-assign it across another builds if required. 

    Next, open a local OSX terminal and connect via SSH, specifying the location of your downloaded secure keypair (.pem) file.

    $ ssh -i <file_path/keypair_file.pem> [email protected]<elastic_ip> 

    If you receive the warning about file permissions just chmod the .pem file to 600.. 

    Accept the certificate entry and once connected re-set the user account password from default.

    $ sudo passwd 

    Update the instance repository sources.

    $ sudo apt-get update 

    And upgrade all packages.

    $ sudo apt-get upgrade 

    To install the LAMP stack use tasksel, check LAMP Server from the list, select OK, and create a MySQL password when asked.

    $ sudo tasksel 

    Once finished input your (Elastic) IP into a browser and if all is well you’ll see the Apache default website text informing you - “It Works..!” 

    You have your LAMP up and running, but how to copy files into it? Well, first let’s open up the web folder to accept data. *NOTE* - 777 is open access, once built drop to a minimum of 755.

    $ sudo chmod -R 777 /var/www 

    To install WordPress, first install phpmyadmin to create the database. Install as follows, inputting your MySQL and Admin user password(s) when requested.

    $ sudo apt-get install phpmyadmin 

    Once installed, access via a browser as advised and log in, select the ‘Privileges‘ tab and create a user with a matched database. You could use the name ‘word_press‘. 

    Next, download your WordPress installation and prepare as described HERE inputting DB_NAME, DB_USER and DB_PASSWORD. 

    An SSH server can already facilitate SFTP file transfer and as our pre-configured AWS security group allows SFTP (SSH – Port 22) we can dive straight in. In Transmit simply configure an SFTP connection to the server IP using the instances username and password. Click the key icon adjacent to the password entry box to specify the location of the keypair (.pem) file and connect. Upload your WordPress files to /var/www and kick off the installation at the following address (containing your own details) http://<your_server_ip>/wp-admin/install.php

    And that’s it, you should now have a working installation of WordPress in an EC2 Ubuntu Virtual Server. 

    There are a couple of things to be aware of with your shiny new build, firstly, as there is no standard Port 21 FTP utility on the server both WordPress and plugin updates will not function from within the application. You can re-configure WordPress for SFTP by installing and configuring the SSH2 package however it’s just as easy to manually upload & delete plugins using SFTP in Transmit. 
    Secondly, there’s the eMail issue, EC2 IP’s are allegedly blacklisted for sending mail, and although personally I've had no problems that's not to say you won't. As such it may be wise to configure some sort of SMTP relaying if you require comment notifications. The WP Mail SMTP plugin should accomodate this, download it HERE, upload, activate & configure.

    Please feel free to comment or get in touch directly if you would like expanded advice on this or any other services we offer.

    No comments:

    Post a Comment