Thursday, December 29, 2011

Install Wordpress over Amazon EC2 instance

 LAMP stack has been installed on my Amazon free EC2 instance, now it's time to get something up and running on it so that I test what an Amazon free micro EC2 instance is capable of. I started with a bare bone CentOS instance with and use it as my sandbox for experiencing things. Wordpress would be a good candidate to try. Below are steps I used to install Wordpress 3.3 to my EC2 instance.
  1. login into AWS Management Console and launch the instance (if it's not running).
  2. Connect to the instance with putty.
    • sudo su
  3. Start Apache and MySQL.
    • service httpd start
    • service mysqld start
  4. login into mysql and create a database for Wordpress
    • mysql> CREATE DATABASE wpdb;
      mysql> GRANT ALL PRIVILEGES ON wpdb.* TO wpuser@localhost
          -> IDENTIFIED BY "wpuser-password";
      mysql> FLUSH PRIVILEGES;
      mysql> exit
  5. Download Wordpress and unpack it.
    • cd /var/www/html
      rm -rf
      cp wp-config-sample.php wp-config.php
  6. Change the ownership of all Wordpress file to Apache - chown -R apache:apache wordpress
  7. Open a browser and type in the Wordpress URL. Following the on screen instruction and Wordpress is up and running in no time.
Of course there is an even quicker way to get Wordpress. There are a number of community AMIs that come with Wordpress pre-loaded and you only need to change wp-config.php to get it up and running.

Wednesday, December 28, 2011

Set up an FTP server on Amazon AWS EC2

You really don't need to set up an FTP server if you simply want to tranfer files between your EC2 instance and your local machine. You can use PSFTP (coming with putty package) with a saved putty session for your EC2 conection. Open a command window, type in psftp your_saved_putty_session_name. Type ec2-user for  login as and you are connected.

If you don't like commandline tool, you can use Filezilla instead. Download and install Filezilla client.  Lauch Filezilla. Click Edit -> Settings and select SFTP under Connction. Click Add Keyfile to add the private key file you use for putty connection. Click OK.

Click File -> Site Manager, Click New Site, enter your AWS EC2's public DNS or IP in Host field. Choose SFTP, enter ec2-user in User field and click Connect.

Now you are connected to your EC2 instance with FileZilla.

If you still want to set up an FTP server on your AWS EC2. Below are steps to install VSFTP.
  1. login to  your AWS management console.
    • Go to EC2 and click the Security Groups link.
    • Then choose the default group and switch to the inbound tab (at the bottom of the page)
    • Add the port ranges as above (20-21 and 40000-41000) and apply the rule changes
  2. connect to your instance with putty.
  3. login as ec2-user
  4. sudo su
  5. yum vsftpd
  6. change the conf file. vim /etc/vsftpd/vsftpd.conf. Add
  7. Add an FTP user (see instruction here)
  8. Start the FTP server. service vsftpd start

Monday, December 26, 2011

Amazon Elastic Compute Cloud (EC2) : Elastic IP

Every time an Amazon EC2 instance is restarted, its public DNS name changes. If you want to use Amazon AWS to host your website, you need a way to map your domain name to an EC2 instance. That's when Amazon's Elastic IP Address comes to play. Elastic IP Address is similar to static IP address, with one key difference. A user can map an Elastic IP Address to any EC2 instance in the AWS console without having to wait for DNS to propagate the new binding.  An Elastic IP Address belongs to the account instance of an EC2 instance. To obtain an  Elastic IP Address, log into AWS management Console,  Click the EC2 tab, then click Elastic IPs link on the left panel.

Click Yes, Allocate to get a new Elastic IP.

Click the Associate Address to map the Elastic IP to an instance.

Pick up an instance from the dropdown box and click Yes, Associate button. Now your EC2 instance is associated with an Elastic IP.

Thursday, December 15, 2011

Add a new user to Amazon EC2 instance

After connecting to your Amazon EC2 instance, you can add a new user with sudo privilege with following steps:
  1. Open a putty session, log in with the default user, ec2-user
  2. sudo su
  3. useradd new_user_name
  4. passwd new_user_name, give a password for the new user
  5. vim /etc/sudoers, insert line "new_user_name ALL = NOPASSWD: ALL" at the end of the file
  6. cd /home/new_user_name
  7. mkdir .ssh
  8. cp ../ec2-user/.ssh/authorized_keys .ssh/authorized_keys
  9. chown -R new_user_name:new_user_name .ssh
  10. chmod 700 .ssh
  11. chmod 600 .ssh/*
Open another putty session and log in with the same private key you use for ec2-user.

Wednesday, December 14, 2011

Amazon announces SMTP Support

Amazon announced that they have added an SMTP interface to its Simple Email Service. According to the announcement, "It is now much easier to configure your programs and applications to send email via Amazon SES. Using your existing systems and SMTP, you don’t have to write a single line of code to send your email. Get started with SMTP today by going to the AWS Management". It's a long waited feature. Can't wait to give it a try.

Tuesday, December 13, 2011

Amazon EC2: Install LAMP stack to it

I have talked about creating an Amazon EC2 account, defining access credentials, launching an instance and connecting to it with putty. Now what? The most logical step next is to load some software to it and start experimenting with it. A very practical way is to configure it as a standalone LAMP stack.
  • Connecting to you instance with putty. Run command sudo su
Install Apache with command: yum install httpd

Install mySQL server with command: yum install mysql-server mysql

Install PHP with command: yum install php php-mysql

Install other optional php packages if you want.

Start Apache server with command: service httpd start.

To test your Apache and PHP install, go to /var/www/html/ directory and create a file index.php with one line of code:
<?php phpinfo(); ?>
In your favorate browser, enter your instance's public DNS name, something like

Monday, December 12, 2011

Amazon Elastic Compute Cloud (EC2) : Part 4: Connect to an Instance with Putty

In Part 3 I talked about launching an instance. I will discuss how to connect to an Amazon EC2 instance with Putty via SSH  step by step.

First import the private key and save it as putty format.

  • Click the Load button, select the private key of the key pair you created before and click Open.

  • You will get the Key import successful message.

  • Click OK, then click Save private Key.

  • You will get a warning message about saving the key without a passphrase, click Yes.

 Next launch Putty to open an SSH session.

Configure Putty to use the PPK file you just saved. Click connection, SSH, and select Auth. Click the browse button next to the Private Key File for authentication field, and select the .PPK file you just created with Puttygen.

Copy your EC2 instance Public DSN to your putty session and click open. Log in with user name ec2-user.

Sunday, December 11, 2011

Amazon Elastic Compute Cloud (EC2) : Part 3: Launch An Instance

In Part 1 and Part 2, I talked about creating an Amazon AWS account and setting up access credentials. In this part, I will talk about launching an instance.

  • If you don't have any key pairs, you can click the Key Pair link under My Resources section to create a key pair.

  • Click the Create Key Pair tab.

  • Enter a Key Pair Name and click Create. Save the generated private key to your computer. After a key pair is created, go back to the EC2 Console Dashboard. Click the Launch Instance Button to start an EC2 instance.

  • From the Request Instances Wizard, you can choose an Amazon Machine Image that meets your needs.  I'll choose the first one, Basic 32-bit Amazon Linux AMI 2011.09.

  • Choose an Instance Type (I choose Micro here), and click Continue. In next screen, use all default values and click Continue.

  • Add tags to your instance and click Continue. I use Name for the Key and my_demo for the Value.

  • Pick up an existing Key Pair or create a new one for connecting to your instance if it launches.

  • Configure Firewall: You can use an existing security group or create an new one. I'm going to create a group here. Click Create a new Security Group radio button, enter a name. Pick up a rule from Create a new rule dropdown box and click Add Rule button. You can define as many rules as you want.
  • Final Review. Everything looks good. Click Launch.

Congratulations, Your first Amazon EC2 instance is up and running!  I will talk about connecting to Amazon EC2 instance in part 4.

Thursday, December 8, 2011

Amazon Elastic Compute Cloud (EC2) : Part 2: Create Access Credentials

You have created an Amazon AWS account (See part 1 for account creation instruction), now let's create access credentials.
Log into your Amazon AWS account, click the Security Credentials On the left Panel. Amazon automatically creates one access key for you when you sign up for an account.

Access Keys screenshot
Let's create X.509 certificates. Go to the X.509 certificates tab and click the link – ‘Create a new certificate’. A private key and an X.509 certificate will be generated for you. Remember to download at least your private key before you close the page. You can rename the file name of download keys to something easy to remember.

Now you have created the X.509 certificates. The final piece you need is Amazon EC2 Key Pairs for launching an Amazon EC2 instance. Click the Key Pairs tab, then the Create a New Key Pair link. Save the private key(rename it if you want). Also download the public key.

Let review what you have so far:
  • AWS account ID
  • Access key ID

  • Secret Access KEY
  • X.509 certificate file (.pem file)
  • X.509 private key file (.pem file you saved to your computer)
  • CloudFront public key file (.pem file)
  • CloudFront private key file (.pem file)
Congratulations, you have completed the setup of your Amazon AWS! In Part 3 I will talk about how to launch an instance and access it from your computer.

Amazon Elastic Compute Cloud (EC2) : Part 1: Sign Up

Amazon EC2 is  is a web service offered by Amazon that provides resizable compute capacity in Amazon's Elastic Compute Cloud. The newly introduced AWS Free Usage Tier provides a very nice playground for developers like me to get their hand on Amazon EC2 for a test drive.
  • Create an account. You can sign in with your existing Amazon account or create a new one. You need to provide payment/credit card information during registration. They will use the phone number you provided to verify your identity. After you click the Call Me Know button, it will display a pin number on the screen. An automated system will dial your number and ask you to enter the pin number through your phone.
  • After your account is created and activated, you need to log into your account to obtain your Access Identifiers to make valid web service requests. There are three types of security credentials associated with your Amazon AWS account.
  1. Access Credentials: Your Access Keys, X.509 Certificates, and Key Pairs. Use access keys to make secure REST or Query protocol requests to any AWS service API. Use X.509 certificates to make secure SOAP protocol requests to AWS service APIs. There are two types of key pairs currently used with specific AWS services — one for Amazon CloudFront and another for Amazon EC2. Use Amazon CloudFront key pairs when creating signed URLs that serve Amazon CloudFront private content. Use Amazon EC2 key pairs to launch and then securely access your Amazon EC2 instances.
  2. Sign-In Credentials: Your E-mail Address, Password, and AWS Multi-Factor Authentication Device. To sign in to secure pages on the AWS web site, the AWS Management Console, the AWS Discussion Forums, and the AWS Premium Support site, you need to provide your Amazon e-mail address and password.
  3. Account Identifiers: Your AWS Account ID and Canonical User ID
I will talk about creating Access Credentials in Part 2.