Table of Contents

Amazon Web Service (EC2)

Amazon Linux for your new instance

Default Spec Sheet

ec2-user default user name
need the key pass
22 ssh port

Common Post-Install Application Spec Sheet

/var/www/html Apache html root
/etc/httpd/conf/httpd.conf Apache server config
sudo service httpd restart Apache server restart command

SSH and File manager

other free pre-config Linux in AWS Marketplace for your new instance

Note

Bitnami Wordpress Linux AMI

Basic
AMI username bitnami
htdoc location: /opt/bitnami/apps/wordpress/htdocs
http.conf /opt/bitnami/apache2/conf/httpd.conf
ftp your_domain.com; user: bitnami; port 22; with key installed in ftp client
Advanced
ssh
ssh -i /path_to_the_key.pem bitnami@your_domain.com
restart apahce
sudo /opt/bitnami/ctlscript.sh restart apache

remove bitnami logo at bottom of page

ref: https://docs.bitnami.com/aws/how-to/bitnami-remove-banner/

Disable PageSpeed on Apache

Check php version and server group

Default path

root /opt/bitnami
server apache2/, mysql/, postgresql/, apache-tomcat
language php/, python/, ruby/, tcl/
app apps/phpMyAdmin/, apps/drupal/, apps/joomla/, apps/redmine/

Backup and New EC2 Instance

Backup important file list in current instance

  1. backup web root (for Amazon AMI, it is under /var/www/html)
  2. backup http.conf (for Amazon AMI, it is under /etc/httpd/conf/httpd.conf)
  3. backup database if you have

Shut down current instance

  1. go Instances tab, action on selected instance
    • stop Instance
    • terminate Instance with volume deletion (it will be auto deleted after 20min)
  2. go Image tab:
    • AMIs: deregister all images (other customized image from your instance created)
    • deregister take about 5 min for it to be gone
  3. go EBS tab:
    • volumes: it should be gone with the instance
    • snapshots: delete all (if not successful, make sure you deregister the AMI associated with it in above step)

Start new instance fresh

  1. Instance tab
    1. launch (create) new instance (here is example of wordpress one)
    2. in the disk image list, go AMS Marketplace: search wordpress, choose “Wordpress by bitnami” (not multisite one)
      • note: this image is based on ubuntu 16.04, and software cost 0 (free), aws instance use still cost like other intance standard charge.
      • note, dokuwiki pre-install ubuntu AMI also available free by bitnami (https://bitnami.com/aws)
      • basically, you don't need to start from a blank scratch Amazon AMI disk image, and setup LAMP and every bit yourself.
      • just continue, with Wordpress
      • choose Instance type (power charge based on instance performance), for free iter, only t1.micro (1cpu,0.6G ram) and t2.micro (1cpu, 1g ram) (t2 > t1)
        • t2.micro (free tier), Next: Configure Instance Details.
    3. configure, leave as default, click “Add Storage”, default 10 gb at least since the wordpress disk image is = 10gb, you can use bigger if you want but not smaller, (free tier can use for 30gb, but after that, 0.12 sgd per GB per month), click Tag instance
    4. tag instance: “Name”:“MyWordPress”, review and Launch
    5. in review page, it show instance spec, and auto security group created by the image template, just click Launch
    6. the key page poped, for download ssh key for the OS (if you have a key before during other intance creation, you can use same key, if not, create a key and download, refer to other article, so you can ssh for advanced linux commandline control in ssh )
    7. After above steps, your instance should be running in your instance tab. with your tagged name (just wait for status from initializing to running)
    8. To find the admin pass, go instance > Action > instance setting > get system log, it will be there with notes like password is, default acc is “user”
  2. link domain name by updating zone file for ip record in Route 53 panel to the instance IP

AWS Route53 - the Domain manager

Move Domain from Godaddy to AWS Route53

Detail Steps

  1. in Godaddy, on your domain DNS page (maybe optional)
    1. export DNS zone file for backup reference
    2. change your DNS server to Route53's AWS DNS server (which you should have done when you moved your hosting to AWS, check on AWS EC setup guide first) (you can get your aws dns server url address in route53 page when trying create zone file. normally 4 dns server urls)
    3. (above step is suggested by AWS page, but later down the road during transfer domain stage, the page give you the option to use it or update DNS server, but if you setup above before hand, the transfer is quicker, and domain is online right after transfer)
  2. in Godaddy, on your domain manage page
    1. under privacy if your have: remove privacy
    2. under domain lock: turn off lock
    3. at the bottom of page, click Get authorization code, which will soon send you a email of the authorization code, which later will be entered on AWS route53 page
    4. once you have the code, click on the bottom of page, “Transfer domain away from GoDaddy”
    5. on the “Transfer domain away from GoDaddy”, it shows you 3 steps
      1. it will try to like you to stay with them and offer you discount, but never mind and click continue
      2. following the page, it may send you email to get confirm if needed. make your email box is open for checking on the side
  3. in AWS route53 page, on the left side panel
    1. click on “registered domains” tab, on the tab panel's top, click “Transfer Domain” button
    2. (Page 1.) Enter the name of your domain, and it will charge your one year of renew fee (that is why sometimes it is good when you domain is about to expire, then make the transfer, but of course give some buffer time, don't do at last minute, like say, 1 month before expire if you like)
    3. and click “Check” button, read the pop-in message if everything is ok or some steps you need to do before you do next, like DNS server setting mentioned before
    4. (Page 2.) next, domain option, where you enter your authorization code, and use 1st name server update option if you have done in above step, I use import name server from a Route 53 hosted zone that has the same name as the domain, which because I did when I was moving the hosting.
    5. (Page 3.) Enter domain contact info
    6. (Page 4.) Review and Purchase
    7. then you will receive a email from AWS about verify the email in contact info, both old email and new email (sometimes you may get the godaddy email first to approve transfer on your godaddy account).
      1. then in confirm page, click Yes for transfer
      2. then transfer is in progress
      3. soon, old domain host provider will email your about domain transfer,
  4. go GoDaddy your domain setting page, the pending transfer out will should on top link, or under domain > domain transfer, click view details
    1. in the pop-up, saying “Status: transfer not started. Accept or Decline”, and click the link and choose Accept to confirm transfer (if you dont do that, transfer will happen after a few days, but if you do that, it will transfer right now)
    2. Now go to domain list, you will see that old domain is not in Godaddy list any more
    3. and transfer should be done in minutes
  5. Then, AWS will email you to confirm your email address in contact info in domain transfer registration. just copy the link and paste to confirm page.
    1. Once you did that, the whole process is successful with notification email sent to you.
  6. go AWS route53 page's left panel, under “Pending requests” tab panel, no more pending transfer
  7. go AWS route53 page's left panel, under “registered domains” tab panel, your domain lives here now
    1. click the domain to review all the contact info and privacy setting
  8. you should get email from both AWS and Godaddy to confirm the final finish notification of domain transfer

Note

Register Domain directly on Route53

S3 Storage

How to use ec2 instance to unzip and send unzip content to S3 Method A

  1. create IAM username ( access key id, access key secret )
    1. Permission : attach policy to IAM, admin, ec2FullAccess
  2. create AMAZON Linux v1 (at the end of process, create key pair)
    1. ssh into ec2 server
      1. aws configure: key id, key secret
      2. region: in url, like “us-west-2”
      3. output format: json
    2. method
      • transfer: aws s3 sync /path/ s3:bucketName/path/ * copy: aws s3 cp /path/ s3:bucketName/path/

How to use ec2 instance to unzip and send unzip content to S3 Method B

  1. IAM service
    • Roles type:
      • new role type: EC2 instance
      • attach policy: S3 full access
    • role name: s3fullaccess_role
  2. launch instance with the role
  3. unzip myFile.zip
  4. make public, or make bucket policy
  5. transfer
    aws s3 sync . s3://my-bucket/path --acl public-read

ref:

Long Term Cost Control

Problem and Fix

Instance is stuck and retiring

Website request not responding

Website Cant Do Editing and Disk is Full

  1. ssh into the server and check disk global size
    df -h
  2. then you will see which partition is full, cd to that place to check each folder
    1. to check current folder size:
      du -sh .
    2. to list all sub folder with size info
      du -sh *
    3. to list all file with size info
      ls -lh
  3. potential Big Size eater
    1. check A: go apache's log folder
      apache2/logs 
      error_log-*.gz
      access_log-*.gz
    2. check B: go apache's mod_pagespeed folder
      // https://docs.bitnami.com/aws/apps/orocrm/administration/use-pagespeed/
      // apache2/var/cache/mod_pagespeed/
      // if you dont use that feature, just delete all inside
      // rm -rf *
      // restart apache 
      // (for bitnami: sudo /opt/bitnami/ctlscript.sh restart apache)
    3. check C: check mysql database folder
      1. login mysql (for bitnami, same as main app pass)
        mysql -u root -p
      2. check database size
        SELECT table_schema AS "Database", 
        ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" 
        FROM information_schema.TABLES 
        GROUP BY table_schema;
      3. check each database's table size
        SELECT TABLE_NAME AS "Table",
        ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
        FROM information_schema.TABLES
        WHERE table_schema = "database_name"
        ORDER BY (data_length + index_length) DESC;
      4. type quit to exit mysql