Difference between revisions of "Amazon AWS Hosted Web Site, start to finish"

From Colettapedia
Jump to navigation Jump to search
Line 98: Line 98:
 
* [http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html Tutorial: Hosting a WordPress Blog with Amazon EC2]
 
* [http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html Tutorial: Hosting a WordPress Blog with Amazon EC2]
 
# <code>wget https://wordpress.org/latest.tar.gz; tar zxvf latest.tar.gz</code>
 
# <code>wget https://wordpress.org/latest.tar.gz; tar zxvf latest.tar.gz</code>
 +
===Setup MySQL user===
 
# <code>mysql -u root -p</code>
 
# <code>mysql -u root -p</code>
 
## <code>CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'some_other_pw';</code>
 
## <code>CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'some_other_pw';</code>
Line 104: Line 105:
 
## <code>FLUSH PRIVILEGES;</code>
 
## <code>FLUSH PRIVILEGES;</code>
 
## <code>exit</code>
 
## <code>exit</code>
 +
===Create and Edit the wp-config.php file===
 +
# <code>cd wordpress; cp wp-config-sample.php wp-config.php</code>
 +
# <code>vim wp-config.php</code>
 +
## <code>define('DB_NAME', 'wordpress-db');</code>
 +
## <code>define('DB_USER', 'wordpress-user');</code>
 +
## <code>define('DB_PASSWORD', 'your_strong_password');</code>
 +
## Go to https://api.wordpress.org/secret-key/1.1/salt to generate unique keys and paste in
 +
===Move all files to web server root===
 +
# <code>mv * /var/www/html/</code>
 +
===Visit the site in your browser and fill in all the details===

Revision as of 19:54, 1 December 2013

Buy the Domain

Initial EC2 Setup

Create Key Pair for SSHing

  • Not possible to specify password when logging into instance, need public key (btw which only works for the region it was created):
  1. Open up Amazon Web Services Console
  2. Open up EC2 Console
  3. Choose your correct region via navigation bar at the top right
  4. On the left navigation pane under "NETWORK & SECURITY," choose Key Pairs
  5. Click Create Key Pair, choose a name for the key pair, probably including the region for which the key pair was created. A .pem file will automatically be downloaded locally. chmod 400 the file. Need to specify the .pem file when SSHing.

Create Security Group

  • Looks like EC2 is pedantic about who can connect. Need to create a white list of which IPs the instance can communicate, both inbound and outbound. Need to put your IP on the list.
  • checkip.amazonaws.com is pretty simple
  • Command line utility traceroute is helpful in figuring out ISP, also has built in IP utility
  1. Open up EC2 Console
  2. If necessary, choose your correct region via navigation bar at the top right
  3. On the left navigation pane under "NETWORK & SECURITY," choose Security Groups
  4. Click Create Security Group, and fill in the details
  5. Click on the Inbound tab and add Rules for HTTP (source=0.0.0.0), HTTPS (source=0.0.0.0), and SSH (your ip address with your.ip.address.boom/32) (always /32 if its your local machine, apparently)

Launch an instance

  1. Console, launch instance
  2. Top choice should be Amazon Linux AMI, default is 64bit instance (Figure out the difference between EBS and HVM)
  3. Micro instance is free tier eligible, selected by default
  4. Click Review and Launch
  5. Edit security group and select the one your just created, then click Review and Launch
  6. Click Launch, bringing up the Key Pair dialog, and select the one you just created, or create a new pair, or select the option not to specify pair
  7. The instance will show up on the dashboard.

Enable billing alert

  • Will let you know when your 12 months are over and your bill will exceed $0.00
  • New style is in the console navigation under Services->Billing
  • Services->CloudWatch, create alarm when billing rises above $0 (Don't forget to change the >= operator to a >)
  • Use 6 hour period, or it might trip the alarm for insufficient data

Connect To Your Instance

  1. Get the public DNS via console, something like ec2-184-73-8-87.compute-1.amazonaws.com
  2. ssh -i /path/key_pair.pem ec2-user@public_dns_name
  3. Edit your ~/.ssh/config file so that you don't have to type in a fuck load of shit

Installing LAMP Web Server

  1. sudo yum update -y
  2. yum grouplist, to see what groups are available
* ec2-user@ip-10-166-48-198 ~
$ yum grouplist
Loaded plugins: priorities, update-motd, upgrade-helper
There is no installed groups file.
Maybe run: yum groups mark convert
Available Groups:
   Console internet tools
   DNS Name Server
   Development Libraries
   Development tools
   Editors
   FTP Server
   Java Development
   Legacy UNIX compatibility
   Mail Server
   MySQL Database
   MySQL Database client
   NFS file server
   Network Servers
   Networking Tools
   PHP Support
   Performance Tools
   Perl Support
   PostgreSQL Database client (version 8)
   PostgreSQL Database server (version 8)
   Scientific support
   System Tools
   TeX support
   Technical Writing
   Web Server
   Web Servlet Engine
Done
  1. sudo yum groupinstall -y "Web Server" "MySQL Database" "PHP Support"
  2. sudo yum install -y php-mysql
  3. sudo service httpd start
  4. sudo chkconfig httpd on to configure Apache to start on boot
  5. chkconfig --list httpd to check runlevels (2, 3, 4, and 5 is desired)
  6. Connect to instance's public DNS to check that it's working

Allow ec2-user to manip web files

  1. sudo groupadd www
  2. sudo usermod -a -G www ec2-user
  3. Logout and log back in to pick up the new group. Type groups to check.
  4. sudo chown -R root:www /var/www changes group ownership of the web dir to www group
  5. sudo chmod 2775 /var/www; find /var/www -type d -exec sudo chmod 2775 {} +
  6. find /var/www -type f -exec sudo chmod 0664 {} +
  7. echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php, check it, and then delete it.

Secure MySQL server

  1. sudo service mysqld start
  2. sudo mysql_secure_installation
    1. Current rot pw by default is nothing so just press enter
    2. Y to set a new pw
    3. Enter new pw twice
    4. Y to the rest of the questions

Setup WordPress

  1. wget https://wordpress.org/latest.tar.gz; tar zxvf latest.tar.gz

Setup MySQL user

  1. mysql -u root -p
    1. CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'some_other_pw';
    2. CREATE DATABASE `wordpress-db`;
    3. GRANT ALL PRIVILEGES ON `wordpress-db`.* TO "wordpress-user"@"localhost";
    4. FLUSH PRIVILEGES;
    5. exit

Create and Edit the wp-config.php file

  1. cd wordpress; cp wp-config-sample.php wp-config.php
  2. vim wp-config.php
    1. define('DB_NAME', 'wordpress-db');
    2. define('DB_USER', 'wordpress-user');
    3. define('DB_PASSWORD', 'your_strong_password');
    4. Go to https://api.wordpress.org/secret-key/1.1/salt to generate unique keys and paste in

Move all files to web server root

  1. mv * /var/www/html/

Visit the site in your browser and fill in all the details