AWS EC2

INFO:
EC2 from Amazon stands for "Elastic Compute Cloud", and is a core component of their cloud based computing services collectively know as Amazon Web Services (AWS).

NOTE: In the following tutorial replace  with your own domain name.

Virtual Private Cloud (VPC) Dashboard
https://eu-west-1.console.aws.amazon.com/vpc/home?region=eu-west-1

Helpful YouTube Video
https://www.youtube.com/watch?v=TjVWpNZfTPE

Default Username and Password
ssh -i your-ssh-key.pem ubuntu@external.dns.name

Thanks AskUbuntu.

Locale Error
If you receive this error on SSH login...

bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.utf8)

...then fix it with these commands...

sudo aptitude install language-pack-en-base sudo update-locale LC_ALL="en_GB.UTF-8" sudo locale-gen sudo dpkg-reconfigure locales locale sudo nano /etc/environment LANG="en_GB.UTF-8" # Add this line to the file sudo reboot

NOTE: Even if you do not receive the error message there is no harm in undertaking the instructions above.

Thanks AskUbuntu.

Copy Instance To A Different Amazon Geographic Region
This is an example of copying an Amazon EC2 Instance from the USA to Ireland.


 * 1) Log in to AWS Console
 * 2) Select AWS Region (top right of screen).
 * 3) Stop Instance.
 * 4) Create Snapshot.
 * 5) Copy Snapshot (to EU West Region - Ireland).
 * 6) Switch AWS Region.
 * 7) Snapshots > right click on Snapshot and choose Create Image.
 * 8) AMI > right click on AMI and choose Launch.
 * 9) Configure Instance as needed.

Official Doc - http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#migrating-instance-availability-zone

Kernel Fix - http://serverfault.com/questions/447980/correct-process-for-starting-new-ec2-instance-from-an-ebs-snapshot

First Doc - http://stackoverflow.com/questions/5402013/move-amazon-ec2-amis-between-regions-via-web-interface

Ubuntu EC2 Images - http://cloud-images.ubuntu.com/locator/ec2/

Installation
sudo aptitude install -y -v lighttpd sudo touch /var/www/favicon.ico sudo nano /var/www/index.html

Log File Setup
sudo nano /etc/lighttpd/lighttpd.conf

Enable the access log module...

server.modules = (   "mod_accesslog", # Add this line in the server.modules section )

Create and add the access log line...

accesslog.filename = "/var/log/lighttpd/access.log"

You can add an optional log file format line...

accesslog.format = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""

Reload the configuarion...

sudo service lighttpd reload

Thanks - http://www.error418.org/2013/02/lighttpd-access-log.html

Log File Rotation

 * NOTE In the following tutorial replace  with your own domain name.

sudo touch /etc/logrotate.d/lighttpd. sudo nano /etc/logrotate.d/lighttpd. /home/lighttpd//logs/*.log { monthly missingok rotate 12 compress delaycompress notifempty sharedscripts postrotate if [ -x /usr/sbin/invoke-rc.d ]; then \ invoke-rc.d lighttpd reopen-logs > /dev/null 2>&1; \ else \ /etc/init.d/lighttpd reopen-logs > /dev/null 2>&1; \ fi; \ endscript }

Save (CTRL+o) and exit (CTRL+x).

Thanks to Cyberciti.

Allow PING
By default EC2 will add a ping rule based on the IP address you are using when you create an machine instance, so to ping from a different IP address you will need to create another rule.

EC2 Dashboard > Network & Security > Security Groups > Select the desired Group ID > Inbound (tab) > / Edit > Add Rule > (Type) Custom ICMP Rule > (Protocol) Echo Request > (Source) Custom IP > Save

Allow HTTP & HTTPS Ports
Separate rules are required for both protocols.

EC2 Dashboard > Network & Security > Security Groups > Select the desired Group ID > Inbound (tab) > / Edit > Add Rule > (Type) TCP > Source (Anywhere, for the entire world) > Save

Additional SSH Locations
By default EC2 will add a SSH login rule based on the IP address you are using when you create an machine instance, so to log in via a different IP address you will need to create another rule.

EC2 Dashboard > Network & Security > Security Groups > Select the desired Group ID > Inbound (tab) > / Edit > Add Rule > (Type) SSH > (Source) Either "My IP" or "Custom IP" (best not to use the "Anywhere" option) > Save

Web Server Virtual Hosts

 * NOTE 1: In the following tutorial replace  with your own domain name.
 * NOTE 2: The following tutorial uses   replace this with your choice of username, i.e. jbloggs.
 * NOTE 3: Items shown like this # This is a comment are just that comments do not run in the terminal or paste them in to files.

sudo mkdir -p /home/lighttpd//{html,logs} sudo useradd -d /home/lighttpd// -s /usr/sbin/nologin -g www-data   sudo passwd   sudo id   sudo touch /home/lighttpd//logs/{access,error}.log sudo touch /home/lighttpd//html/{favicon.ico,index.html} sudo nano /home/lighttpd//html/index.html  # Add your domain name to the file then save and exit sudo chown -R www-data:www-data /home/lighttpd/ sudo chown -R  :www-data /home/lighttpd// sudo chmod g+w /home/lighttpd//logs/* sudo nano /etc/lighttpd/lighttpd.conf include ".conf" # Add this line to the end of the file then save and exit sudo nano /etc/lighttpd/.conf $HTTP["host"] =~ "(^|\.)domain\.com$" { server.document-root = "/home/lighttpd/<yourdomainname.com>/html" server.errorlog = "/home/lighttpd/<yourdomainname.com>/logs/error.log" accesslog.filename = "/home/lighttpd/<yourdomainname.com>/logs/access.log" # uncomment below for wordpress # url.rewrite-if-not-file = ( "^/(wp-.+).*/?" => "$0", "^/keyword/([A-Za-z_0-9\-]+)/?$" => "/index.php?keyword=$1", "^/.*?(\?.*)?$" => "/index.php$1" ) } sudo service lighttpd reload

Thanks to Cyberciti.

Backup Of EC2 Instance
Thanks - http://www.techrepublic.com/blog/the-enterprise-cloud/backing-up-and-restoring-snapshots-on-amazon-ec2-machines/