Saturday 15 April 2017

Install WordPress on AWS EC2 Instance

WordPress and AWS
After successful completion of first and second step i.e. creating an EC2 instanceand connecting to EC2 instance in AWS using PuTTY and Terminal respectively. Further moving ahead, it is time to install Apache, PHP, MySQL to run WordPress on an EC2 instance. If you are not familiar with command line / Linux commands just run these commands in same order.

NOTE: This instruction is for Amazon Linux and will not work if you are trying different machine image like Ubuntu or Windows Server.

Connect to your instance via PuTTY  (Windows) / Terminal (Mac OS) / Bash (Linux OS)

Just to make sure everything is up to date
sudo yum -y update

If you want, you may directly switch from ‘ec2-user’ user to root using sudo su command.

Install multiple software packages:
sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd

Start Apache Server:
sudo service httpd start

Create a page to check your PHP installation

a) vi test.php
b) Type i to start the insert mode
c) Type <?php phpinfo() ?>
d) Hit escape button and type :wq, now hit enter to exit
e) Open a browser and (use you public IP DNS followed by /test.php)

If you see a phpinfo page then you are good to move forward, otherwise you may want to start over.

Delete the test.php file as it is for the information only and you definitely don’t want to give away sensitive information about your server:

rm -f /var/www/html/test.php

Secure Start SQL service

Start MySQL service and run secure installation
sudo service mysqld start
sudo mysql_secure_installation

When prompted, enter a password for the root account. By default, the root account does not have a password set, so press Enter.

Type Y to set a password, and enter a secure password twice
1) Remove anonymous users? [Y/n] Y
2) Disallow root login remotely? [Y/n] Y
3) Remove test database and access to it? [Y/n] Y
4) Reload privilege tables now? [Y/n] Y

Restart MySQL to pick up the changes:
sudo service mysqld restart

Login into MySQL and Create a database for WordPress

Log in to the MySQL server as the root user and enter your MySQL root password when prompted
mysql -u root –p

Create a user name and password for your MySQL database.
CREATE USER 'aksgeek'@'localhost' IDENTIFIED BY 'aksgeekpassword';
Replace ‘aksgeek’ with your WordPress username and ‘aksgeekpassword’ with your strong password.

Create a database for WordPress:


CREATE DATABASE `wordpressdb`;

(you can create a database with any name)

GRANT ALL PRIVILEGES ON `wordpressdb`.* TO "aksgeek"@"localhost";


Install WordPress
cd /var/www/html
tar -xzf latest.tar.gz
cd wordpress/
mv wp-config-sample.php wp-config.php
nano wp-config.php

Start editing wp-config.php. (user arrow keys to move around)

define('DB_NAME', 'wordpressdb');
define('DB_USER', 'aksgeek');
define('DB_PASSWORD', 'aksgeekpassword');
define('DB_HOST', 'localhost');

Visit to randomly generate a set of key values that you can copy and paste into your wp-config.php file.
Ctrl + X
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ? Y
File Name to Write [DOS Format]: wp-config.php  hit Enter.

Move your WordPress installation to root or in subdirectory / folder

You may want to run your WordPress blog from root like  then
mv * /var/www/html/


Most of you want to install it in a subdirectory or folder (for example,, then
mkdir /var/www/html/blog
mv * /var/www/html/blog

To allow WordPress to use permalinks
sudo nano /etc/httpd/conf/httpd.conf

<Directory "/var/www/html">
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    # The Options directive is both complicated and important.  Please see
    # for more information.
    Options Indexes FollowSymLinks

    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    AllowOverride None

    # Controls who can get stuff from this server.
    Require all granted

Find the section that starts with <Directory "/var/www/html"> and change the AllowOverride None line to AllowOverride All.

To ensure that the httpd and mysqld services start at every system boot
sudo chkconfig httpd on
sudo chkconfig mysqld on

Open a web browser and enter the URL of your WordPress blog, you should see the WordPress installation screen

Example for root installation:


for subdirectory / folder (blog):


Enter your site name, username, password and email address and hit submit.

Congratulations!! You are running WordPress blog on Amazon Web Services (AWS) EC2 instance.


Having trouble updating and downloading themes/plugin in WordPress blog as it is asking for FTP credentials then run this command:
sudo chown -R apache:apache /var/www/html


Post a Comment