“Learn, Learn and Learn”



Here we are going to discuss how can we setup a wordPress website on AWS EC2 within few minutes. There are several platforms which gives you the option to pay for their services and have a WordPress site. Then you can build whatever you need to do. But today we will discuss how to build our own server, install WordPress and setup the rest.

What is the benefits of choosing AWS to setup WordPress ?



Because you don’t need to pay for services which other platforms provides. In AWS, you are the owner of your server and you are the person who install and setup your installation. So no monthly charges for anonymous companies . Only pay is for as you go. From this article we will learn how to setup our own WordPress site. In AWS also there are options to use pre-installed WordPress and make our site. But here we will discuss how to setup a wordpress website on AWS without using any pre-installations.

Follow the steps as below.



1) First we need to create a AWS EC2 instance.



Log into your AWS account – https://aws.amazon.com/

Go to EC2 in your dashboard

Create a new EC2 instance

I selected a Amazon Linux AMI as the operating system.

Select the Instance type as a General Purpose t2.micro

Keep the storage as it is.

Configure the Security group. Select Create a new security group. Give a name and a description. Add a SSH rule to the table with source of Your own IP address.

Finally launch the new instance.

You have to create a key pair ( public and a private key ) in order to connect to your instance.

I had a created key pair named “my”. You have to download putty-gen software and create a key pair.

Follow the page to download and setup key pair by using putty-gen – https://www.puttygen.com/

My new EC2 instance is now UP and Running.

Take your public DNS address and connect to it using Putty.

Now we have done the server creation part. Next we have to do the Installation of WordPress and setting up other packages.

2) Log into your newly created EC2 instance



Switch as root.

Install Apache web server

command – yum install httpd -y







start the apache service

command – service httpd start









Test your web server from the web browser. Use your public DNS.

*Important – Check whether you have added HTTP as an inbound rule to your security group.







If port 80 is not enabled from your security group, you can’t check your apache web server from the web browser.

Install PHP

command – yum install php php-mysql







Restart Apache service after installing PHP.

command – service httpd restart



Test your php Installation

commands

cd /var/www/html

vi test.php



Go to the directory path of /var/www/html and create a file named test.php and press i to edit the file.

Type <?php phpinfo() ?>

and save the file ( ESC + :wq )

Now check your php installation by accessing test.php file from the browser.

eg – <Your public DNS>/test.php

You should have a database for the posts and your user’s comments to be stored. So we are create a mysql database.

Install mysql

command – yum install mysql-server -y



start mysql service

command – service mysqld start



Create your database for the site

commands as below



mysqladmin -u root create blog

mysql_secure_installation



Give the answers as below

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

Now install WordPress application

commands



cd /var/www/html

wget http://wordpress.org/latest.tar.gz







Extract the compressed zip file

command – tar xzfv latest.tar.gz







After extracting the latest.tar.gz file, we get a directory named wordpress.



We will rename the directory from wordpress to blog.

command – mv wordpress blog



Go inside the blog folder

cd blog

mv wp-config-sample.php wp-config.php

wp-config.php file Edit thefile command – vi wp-config.php



Change the values as below define(‘DB_NAME’, ‘blog’);

define(‘DB_USER’, ‘root’);

define(‘DB_PASSWORD’, ‘YOUR_PASSWORD’);

define(‘DB_HOST’, ‘localhost’);

Save the changes.

Restart your mysqld and httpd service.

service mysqld restart

service httpd restart

Then test the wordpress blog from the browser.

ec2-35-173-213-98.compute-1.amazonaws.com/blog

My Output was like below

This tells that php installation should be at least 5.6. So we need to upgrade php version. Let’s dig into that. First we will stop Apache service and will remove it. commands

service httpd stop

sudo yum erase httpd httpd-tools apr apr-util Remove old php yum remove php-* Install PHP 5.6 yum install php56 Install mysql extension yum install install php56-mysqlnd Restart httpd service service httpd restart Check your php version php -v Output would be like below. Now go to the browser and try to access your <Public DNS>/blog Awesome. We have come to the last steps. Now we will setup the credentials for our WordPress. Fill in the blanks as mentioned in above image. Give a Site title, username for your WordPress admin dashboard. Keep the password in a safe place. Give a email address and put the tick for Search Engine visibility.

The username and password is the credentials used to manage your WordPress dashboard. You will redirect to the admin page. See the admin dashboard. From this place you can control everything in your WordPress site. Access your WordPress site like below.

So your site will looks like below.

If you want to change the theme, Try as below.

After activating the new theme, below will be the appearance.

Now we have setup our own WordPress site. You can build up now your own blog or website as your wish. There are so many plugins, themes and so many features in WordPress. You can use WordPress to create a very attractive website.

Recommended permission changes



Grant the ownership as Apache for all files and directories under /var/www

sudo chown -R apache:apache /var/www



Change the directory permissions in /var/www



chmod 2775 /var/www

find /var/www -type d -exec sudo chmod 2775 {} ;



Change the file permissions as well

find /var/www -type f -exec sudo chmod 0664 {} ;



Restart Apache service to affect the permission changes

service httpd restart

So, Finally we learned completly how to setup a wordpress website on AWS. If you have any questions please comment below.

Useful resources



Cheers.