Step 1: Create an Amazon Web Services (Hereafter AWS) Account
First things first: Create your AWS account. Provide a credit card and a phone number and AWS will call you to verify your details. Amazon offers a Free Usage Tier, which is greatly beneficial to explore AWS services and even host real apps without being hugely charged. Check the details here.
Step 2: Prerequisites to launch EC2 instance:
Create new IAM User and add it to administrator group or use default administrator role created while sign up. Create Keypair and download to login to instance using CLI. Create new VPC or use default VPC. Create Security group to allow inbound and outbound traffic and attach security group to default VPC/Self made VPC. ( For an instance you can allow “all traffic”.)
PS: You will need to allow SSH, HTTP, MySQL traffic to communicate with instance.
Step 3: Create an Instance
What type of EC2 instance should you use?
Well, Choosing right instance depends upon many factor such as traffic, usage etc, which require detailed analysis for your usage, product and services. Right now, for initial WordPress installation use t2-Micro instance (Free tier eligible) However, t2-Micro instance doesn’t work properly with heavy traffic websites.
To create a new instance, access the AWS Management Console and click the EC2 tab:
- Choose an AMI in the classic instance wizard: chose the Basic 32-bit Amazon Linux AMI.
- Now review your configuration and launch t2-micro EC2 Instance.
- Instance details: Select the Instance Type you want to use. I chose micro (t2.micro)
- Choose default VPC and Subnets.
- Enable Auto Assign public IP
- Choose IAM role ( If not created, select none)
- Add storage for your instance : for t2-micro instance you can choose default 8GiB storage.
- Assign previously created security group or create new security group and attach it to EC2 Instance.
- Choose Existing Key pair or Create New key pair
Step 3: SSH into your Instance
Once your instance is up and running, Login to Instance using SSH. Grab public IP address of EC2 Instance and SSH to it.
Use that address (and a path to your .pem file) to ssh into your instance:
Command: ssh email@example.com -i ~/wpaws.pem
If you get a message about your .pem file permissions being too open, chmod your .pem file as follows:
chmod 600 ~/wpaws.pem
Many of the shell commands below require root access. To avoid having to prefix these commands with sudo, let’s just switch user once and for all:
Step 4: Install the Apache Web Server
To install and update Apache Web Server,:
yum install httpd
Start the Apache Web Server:
service httpd start
To test your Web Server, open a browser and access your web site: ec2-184-72-78-72.compute-1.amazonaws.com (Use your actual public DNS name). You should see a standard Amazon place holder page.
Step 5: Install PHP
To install PHP, type:
yum install php php-mysql
Restart the Apache Web Server:
service httpd restart
Create a page to test your PHP installation:
cd /var/www/html vi test.php
. Type i to start the insert mode
. Type <?php phpinfo() ?>
. Type :wq to write the file and quit vi
Open a browser and access test.php to test your PHP installation: ec2-184-72-78-72.compute-1.amazonaws.com (Use your actual public DNS name).
Step 6: Install MySQL
To install MySQL, type:
yum install mysql-server
service mysqld start
Create your “blog” database:
mysqladmin -uroot create blog
Secure your database:
Answer the wizard questions as follows:
. Enter current password for root: Press return for none
. Change Root Password: Y
. New Password: Enter your new password
. Remove anonymous user: Y
. Disallow root login remotely: Y
. Remove test database and access to it: Y
. Reload privilege tables now: Y
Step 7: Install WordPress
To install WordPress, type:
cd /var/www/html wget http://wordpress.org/latest.tar.gz tar -xzvf latest.tar.gzcd
This will uncompress WordPress in its own “wordpress” directory. I like having WordPress in a separate directory, but would rather rename it to “blog”:
mv wordpress wordpress
Create the WordPress wp-config.php file:
cd blog mv wp-config-sample.php wp-config.php vi wp-config.php
. Type i to start insert mode.
. Modify the database connection parameters as follows:
define(‘DB_NAME’, ‘wordpress’); define(‘DB_USER’, ‘root’); define(‘DB_PASSWORD’, ‘YOUR_PASSWORD’); define(‘DB_HOST’, ‘localhost’);
. Type :wq to write the file and quit vi
Open a Browser and access your blog: ec2-184-72-78-72.compute-1.amazonaws.com (Use your actual public DNS name). This should trigger the WordPress configuration process.
Step 8: Map IP Address and Domain Name
To use your blog in production, you will have to:
. Associate an IP address to your instance
. Map your domain name to that IP address
. Change and Update CNAME records and even MX records for mailing.
To associate an IP address to your instance:
. In the AWS Management Console, click Elastic IPs (left navigation bar)
. Click Allocate New Address, and confirm by clicking the “Yes, Allocate” button