installing wordpress on aws

59
August 2013 Installing WordPress on AWS EC2 RDS S3 EBS

Upload: manish-jain

Post on 02-Dec-2014

32.466 views

Category:

Technology


11 download

DESCRIPTION

A complete step by step tutorial to install WordPress on Amazon's AWS platform. Using EC2, EBS, RDS and S3.

TRANSCRIPT

Page 1: Installing WordPress on AWS

August 2013

Installing WordPress on AWS

EC2 RDS S3EBS

Page 2: Installing WordPress on AWS

What is CoveredSlide Topic3 Architecture Overview4 Signup for AWS5-13 Part 1: Create an EC2 Instance14-16 Part 2: Configure your EC2 Instance17-27 Part 3: Create an RDS Instance28-33 Part 4: Install WordPress34-37 Part 5: Configure S338-52 Part 6: Install Git53 Done.

Page 3: Installing WordPress on AWS

Users

Internet

The AWSinfrastructurefor this tutorial

Elastic Compute

Cloud (EC2)

ElasticBlockStore (EBS)

RDSMySQL

Simple Storage

Service (S3)

Availability Zone: US-East-1b

Page 4: Installing WordPress on AWS

Create your free account on AWS - http://aws.amazon.com/free/

Page 5: Installing WordPress on AWS

Part One:Create an EC2 instance

In AWS-speak creating a new virtual server is called an “instance”. “Spinning up an EC2 instance” is a phrase you will hear quite often which just refers to starting a new EC2 instance.

EBS refers to the “hard drive” that is attached to the EC2 instance. It’s where all the system files will reside.

Page 6: Installing WordPress on AWS

Step 1: From the AWS Management Console click on EC2

Page 7: Installing WordPress on AWS

Step 2: Click on “Launch Instance” and select Quick Launch Wizard(Enter the Instance name, create a new key pair, download the key pair and select Ubuntu Server 12.04)

Page 8: Installing WordPress on AWS

Step 3: Select Amazon Linux AMI(Under Instance Details make sure t1.micro is selected it’s part of the free trial, then select Launch)

Page 9: Installing WordPress on AWS

Step 4: Your instance is being created

Page 10: Installing WordPress on AWS

Step 5: Add rules to the Default Security Group to allow inbound access to EC2(port 22 = ssh and port 80 = http)

Page 11: Installing WordPress on AWS

Step 6: Assign an IP address by selecting Elastic IP’s

Page 12: Installing WordPress on AWS

Step 7: Right click on the IP address and select Associate. Assign it to your new instance.

Page 13: Installing WordPress on AWS

Step 8: Select your new Instance and right click on it(this contains some very useful information you might need later on)

Page 14: Installing WordPress on AWS

Part Two:Configure your EC2 instance

Now that the EC2 instance has been created it’s time to install the LAMP (Linux, Apache, MySQL and PHP) stack which we’ll need before you can install WordPress. The Linux kernel was preinstalled when the EC2 instance was created. Apache and PHP will be installed in this section. MySQL will be installed in the next section.

Page 15: Installing WordPress on AWS

There are two ways you can connect to EC2, one is to right click on the EC2 instance name and launch a Java SSH client. The other way is to use a command line SSH client such as Terminal.app on the Mac. This tutorial will use Terminal.

Step 1: Connect to the EC2 instance

Page 16: Installing WordPress on AWS

From Terminal go to the directory that contains <filename>.pem (the file contains your credentials to access your EC2 instance.)

Change the permission of the file:chmod 400 [filename].pem

Connect to your EC2 instance:ssh -i [filename].pem ubuntu@[Elastic IP]

Switch to superuser:sudo su

Install any new updates:sudo apt-get update

Install Apache:apt-get -y install apache2

Install PHP:apt-get -y install php5 php5-mysql

Step 2: Install Apache and PHP

Page 17: Installing WordPress on AWS

Part Three:Create an RDS MySQL instance

Page 18: Installing WordPress on AWS

Step 1: From the Management Console click on RDS and then select Launch a DB Instance

Page 19: Installing WordPress on AWS

Step 2: Select MySQL Community Edition

Page 20: Installing WordPress on AWS

Step 3: Select db.t1.micro, no for Multi-AZ(db.t1.micro is part of the Free Trial. Remember the Master Username and Master Password for WordPress)

Page 21: Installing WordPress on AWS

Step 4: Enter a Database Name(Remember the Database Name for WordPress)

Page 22: Installing WordPress on AWS

Step 5: Select the defaults

Page 23: Installing WordPress on AWS

Step 6: Select Launch DB Instance

Page 24: Installing WordPress on AWS

Step 7: The database may take 5 minutes to create

Page 25: Installing WordPress on AWS

Step 8: Click on DB Security Groups and click on the magnifying glass

Page 26: Installing WordPress on AWS

Step 9: Verify the EC2 Security Group is authorized

Page 27: Installing WordPress on AWS

Step 10: Click on Instance and review the informatio for the DB you created(Remember the Endpoint for WordPress)

Page 28: Installing WordPress on AWS

Part Four:Install WordPress

WordPress will be installed at the root of your EC2 Instance.

Page 29: Installing WordPress on AWS

From Terminal go to the directory that contains <filename>.pem

Change the permission of the file:chmod 400 [filename].pem

Connect to your EC2 instance:ssh -i [filename].pem ubuntu@[Elastic IP]

Switch to superuser:sudo su

Change to the root directory:cd /var/www

Download the latest WordPress package:wget http://wordpress.org/latest.tar.gz

Extract WordPress:tar -xzvf latest.tar.gz

Move WordPress to the root www folder:mv wordpress/* /var/www/

Delete the WordPress tar file and the existing index.html filerm latest.tar.gzrm index.html

Change permissions on the directory:chown -hR www-data:www-data /var/wwwchmod -R g+rw /var/www

Restart the Apache serverservice apache2 restart

Step 1: Download and install WordPress

Page 30: Installing WordPress on AWS

Step 2: Point your browser to the Elastic IP address and create the config file

Page 31: Installing WordPress on AWS

Step 3: Enter the configuration details and submit

Page 32: Installing WordPress on AWS

Step 4: Finish the installation of WordPress

Page 33: Installing WordPress on AWS

Step 4: Goto your Elastic IP address and visit your new blog

Page 34: Installing WordPress on AWS

Part Five:Configure S3

S3 will be used to serve up media images (jpg, png, etc...) on the WordPress blog. S3 uses the term “bucket”, think of it as a container for your files. The bucket name has to be unique across the entire S3 platform.

Page 35: Installing WordPress on AWS

Step 1: From the Management Console click on S3 and select Create Bucket

Page 36: Installing WordPress on AWS

Step 2: Enter a bucket name

Page 37: Installing WordPress on AWS

Step 3: Click on Upload and add an image(Use the S3 link when adding an image to a blog post in WordPress)

Page 38: Installing WordPress on AWS

Part Six:Install Git

Git is a powerful distributed version control system. For this tutorial we’ll be using Git on the EC2 instance, SourceTree an open source Git Mac client and Beanstalk* a service to manage and deploy code. Beanstalk has a free trial plan.

BeanstalkSourceTree

* Beanstalk should not be confused with Elastic Beanstalk which is an AWS offering to manage your application.

Not 100%

tested

Page 39: Installing WordPress on AWS

EC2Staging Server

Beanstalk

Architecture of Git

User X(running Git and

SourceTree)

User Y(running Git and

SourceTree)

Users

EC2Production Server

AWS

Page 40: Installing WordPress on AWS

1. Goto http://git-scm.com/downloads/ and download the latest version of Git. Double click on the installer and follow the directions.

2. Download SourceTree an open source Git client from http://www.sourcetreeapp.com and follow the instructions to install and configure it.

3. Open a terminal window

Goto the hidden SSH directory in your home directory:cd ~/.ssh

Generate a key (don’t enter any passphrase):ssh-keygen -t rsa

Copy the generated key to the clipboard (needed for Beanstalk):cat ~/.ssh/id_rsa.pub | pbcopy

Step 1: Install Git on your local computer

Page 41: Installing WordPress on AWS

1. Goto http://beanstalkapp.com and setup an account (it’s free for one user).

2. Add your computers SSH key to the account by going to:https://<your-account>.beanstalkapp.com/public_keys

Step 2: Setup Beanstalk

3. Click on Add Public Key 4. Add your SSH key which is in the clipboard (⌘+P)

Page 42: Installing WordPress on AWS

5. Add a repository by going to https://<your-account>.beanstalkapp.com/repositories and click on Create a repository

Setup Beanstalk (cont.)

Page 43: Installing WordPress on AWS

6. Give it a name and select “Git” for type and click Next Step

Setup Beanstalk (cont.)

Page 44: Installing WordPress on AWS

7. Copy the Git URL

Setup Beanstalk (cont.)

Page 45: Installing WordPress on AWS

8. Launch SourceTree and click on the icon with the database and plus symbol and add the Git information from Beanstalk. You have successfully cloned the empty repository on Beanstalk to your local computer.

Setup Beanstalk (cont.)

Page 46: Installing WordPress on AWS

9. Before we can setup the Deployment Servers in Beanstalk, you need to commit and push a change to Beanstalk. Add a file to the local destination path and then refresh SourceTree. Commit the file and push the change.

Setup Beanstalk (cont.)

Page 47: Installing WordPress on AWS

In Beanstalk we will configure the server that will have the code deployed to. From the Repository tab click on Deployment and select Create Server & Environment

Step 3: Final setup for Beanstalk (cont.)

Page 48: Installing WordPress on AWS

Select SFTP for the server type.

Step 3: Final setup for Beanstalk (cont.)

Page 49: Installing WordPress on AWS

Enter the details of your EC2 instance. Click on “download the key” you will be coping this to your EC2 instance. (DO NOT click “Check Connection”, that will be in the next step)

Step 3: Final setup for Beanstalk (cont.)

Page 50: Installing WordPress on AWS

Copy the <repository-name>.pub deployment key to your EC2 instance in the /home/ec2-user/ directory

Then from a terminal window add the <repository-name>.pub file to the EC2 authorized keys file:cat <repository-name>.pub >> ~/.ssh/authorized_keys

Now click on “Check Connection”

Step 3: Final setup for Beanstalk (cont.)

Page 51: Installing WordPress on AWS

Click on Next Step

Step 3: Final setup for Beanstalk

Done. You can now start to push code to your EC2 instance from Beanstalk.

Page 52: Installing WordPress on AWS

From Terminal go to the directory that contains <filename>.pem (the file contains your credentials to access the EC2 instance.)

Change the permission of the file:chmod 400 [filename].pem

Connect to your EC2 instance:ssh -i [filename].pem ubuntu@[Elastic IP]

Switch to superuser:sudo su

Install Git:apt-get -y install git

Create a new directory:mkdir /var/www/ferrari

Setup a Git repository:mkdir /var/www/ferraricd /var/www/ferrarigit init --bare

Copy the <repository-name>.pub file to EC2 then copy the <repository-name>.pub file to the EC2 authorized keys file:cat beanstalk_rsa.pub >> ~/.ssh/authorized_keys

Step 4: Install Git on EC2

Page 53: Installing WordPress on AWS

Done.Now What?

Make things and break things to learn how all the various services of AWS work together. Visit AWS for more tutorials at:

http://aws.amazon.com/articles/

Page 54: Installing WordPress on AWS

Created by:Manish Jain

The backstory to why this presentation was created can be found on my blog at:

http://celestri.org/

Page 55: Installing WordPress on AWS

AppendixRandom Slides

Page 56: Installing WordPress on AWS

Create and edit the config file:cd /var/wwwmv wp-config-sample.php wp-config.phpnano wp-config.php

Quick nano tutorial – Control-X to exit.

You will need to edit the following entries in the config file with the values from your RDS MySQL instance:

define(‘DB_NAME’, ‘wordpress’);define(‘DB_USER’, ‘root’);define(‘DB_PASSWORD’, ‘YOUR_PASSWORD’);define(‘DB_HOST’, ‘localhost’);

Below is a mapping of the WordPress config file and the RDS MySQL instance:

‘DB_NAME’ = Database Name‘DB_USER’ = Master Username‘DB_PASSWORD’ = Master User Password‘DB_HOST’ = RDS Endpoint

Instructions to manually edit the WordPress config file

Page 57: Installing WordPress on AWS

From Terminal go to the directory that contains <filename>.pem

Change the permission of the file:chmod 400 [filename].pem

Connect to your EC2 instance:ssh -i [filename].pem ubuntu@[Elastic IP]

Switch to superuser:sudo su

To install MySQL:apt-get install -y mysql-server

Create a root password for MySQL when prompted

Enter into the MySQL shell to enter the commandsmysql -u root -p(enter the password when prompted)

Now you are in the MySQL shell and will create a new database, you should see mysql>CREATE DATABASE wordpressAWS;

Create a new user:CREATE USER myadmin@localhost;

Set the password for the newly created user:SET PASSWORD FOR myadmin@localhost = PASSWORD(“whatever”);

Instructions to install MySQL on an EC2 instance

Page 58: Installing WordPress on AWS

Grant all privileges to the newly created user:GRANT ALL PRIVILEGES ON wordpressAWS.* TO myadmin@localhost IDENTIFIED BY “whatever”;

Then refresh MySQL:FLUSH PRIVILEGES;

Exit the MySQL shell:exit

From the command line secure your database installation:mysql_secure_installation

Instructions to install MySQL on an EC2 instance (continued)

Page 59: Installing WordPress on AWS

Cyberduck is an open source FTP/SFTP client. Enter the details below to configure it.

Use Cyberduck to copy files to EC2

Your [filename].pem

Select SFTP

Enter ubuntu