Recents in Beach

How to host wordpress website in AWS cloud with EC2 Instance ?

Step 1: Create an AWS Account



First things first: you need to create your AWS account. You can sign up here. You must provide a credit card and a phone number where you will be asked to be part of the online registration process for verification purposes. Amazon offers a free usage tier, which is great for locating services and even hosting without charging the actual application. Check the details here.

Step 2: Create an Instance

What type of EC2 instance should you use?I started my experiments with a micro example because its price structure is very attractive. However, for a few hours after a few minutes, my blog became systematically unresponsive and I had to restart Apache and / or MySQL. I did some research, and found out that other people were reporting similar problems. This may depend on your blog traffic. My blog usually gets a few thousand pages a day. It also runs a live sample application running on a PHP or Java back-end on Tomcat. It seems that the combination was too much for a micro example. I gave a small example and the problems went away. 
To create a new instance, access the AWS Management Console and click EC2 tab:
  • Choose an AMI in the classic example wizard: I chose the Basic 32-bit Amazon Linux AMI.
  • Instance details: Select the Instance Type you want to use. for eg: Small (m1.small).
  • Create a new key pair. Enter a name for your key pair (i.e. christophe) and download your key pair (i.e. techtalks.pem).
  • Select the quick start security group.
  • Launch your instance.

Step 3: SSH into your Instance

Once your instance is running, you can ssh into it. First, you need to identify the address of your instance: Select the instance in the AWS management console, and look for the public DNS in the instance (bottom part of the screen).

Use that address (and a path to your .pem file) to ssh into your instance:
ssh ec2-user@ec2-50-17-14-16.compute-1.amazonaws.com -i ~/christophe.pem
If you get a message about your .pem file permissions being too open, chmod your .pem file as follows:
chmod 600 ~/christophe.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:
sudo su

Step 4: Install the Apache Web Server

To install the Apache Web Server, type:
yum install httpd
Start the Apache Web Server:
service httpd start
To test your Web Server, open a browser and access your web site: http://ec2-50-17-14-16.compute-1.amazonaws.com (Use your actual public DNS name). You should see a standard Amazon place holder page.

Step 5: Install PHP

yum install php php-mysql
Restart the Apache Web Server:
service httpd restart
Create a page to test PHP installation:
cd /var/www/html
vi test.php
  1. Type i to start the insert mode
  2. Type <?php phpinfo() ?>
  3. Type :wq to write the file and quit vi
Now, Open a browser and access your test.php to test your PHP installation: http://ec2-50-17-14-16.compute-1.amazonaws.com/test.php (Use your actual public DNS name).

Step 6: Now, Install MySQL

1) To install MySQL, type:
"yum install mysql-server"
2) Start MySQL:
service mysqld start
3) Create your “blog” database:
mysqladmin -uroot create blog
4) Secure your database:
mysql_secure_Installation
Follow these: 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: Now, Install WordPress application

To install WordPress, type following:
cd /var/www/html
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gzcd
This will un compress WordPress in its own “wordpress” directory. I Personally like having WordPress in a separate directory, but would rather rename it to “blog”:
mv wordpress blog
Create the wp-config.php file:
cd blog
mv wp-config-sample.php wp-config.php
vi wp-config.php
  1. Type i to start insert mode.
  2. Modify the database connection parameters as follows:
    define(‘DB_NAME’, ‘blog’);
    define(‘DB_USER’, ‘root’);
    define(‘DB_PASSWORD’, ‘YOUR_PASSWORD’);
    define(‘DB_HOST’, ‘localhost’);
  3. Type :wq to write the file and quit vi
Open the Browser and access your blog: http://ec2-50-17-14-16.compute-1.amazonaws.com/blog (And, Use your actual public DNS name). This will trigger the WordPress conf process.

Step 8: Map Your Server IP Address and Domain Name

To use your blog in live environment, you will have to:
  1. Associate an IP address to your instance EC2
  2. Map your domain name to that IP address
To associate an IP address to your instance:
  1. In the AWS Management Console, click Elastic IPs (left navigation bar)
  2. Click Allocate New Address, and confirm by clicking the “Yes, Allocate” button
  3. Right-click the newly allocated IP address and select “Associate” in the popup menu. Select the instance you just created and click “Yes, Associate”
To map your domain name to your IP address, you will have to use the tools provided by your domain registrar. If you use GoDaddy, specify NS73.DOMAINCONTROL.COM and NS74.DOMAINCONTROL.COM as the name servers for your domain, and use the DNS Manager to modify the A record and point to your IP address. Documentation is available here.

Once everything is configured and mapped correctly, access the general settings in the WordPress Management Console and make sure that the WordPress address and site address are specified using your domain name as the screenshot below.

Post a comment

0 Comments