Steps to setup a WordPress blog on the Amazon EC2 infrastructure.

GOKUL G. NAIR
3 min readApr 19, 2023

--

Are you looking to start a WordPress blog? Amazon EC2 provides a cloud infrastructure where you can host your blog. In this tutorial, we will walk through the steps to set up a WordPress blog on Amazon EC2.

Prerequisites Before we start, you will need the following:

  1. Putty and PuttyGen installed on Windows (or ready for use)
  2. Basic understanding of Linux concepts and commands. Know how to use Putty and optionally understand security concepts.
  3. An Amazon AWS account. A credit card signup is required even though the basic Linux instance (micro instance) is free for 12-months.

Part A — Setting up the EC2 Instance

  1. Login to the Amazon AWS console and select EC2 — Virtual servers in the cloud.
  2. Under Create Instance, click on Launch Instance.
  3. Select Amazon AMI Linux — 64 bit.
  4. Check the settings and maintain defaults. Keep clicking next until you reach the Configure Security Group section.
  5. Click Add Rule twice — once for the HTTP (port 80) and another for the HTTPS (port 443). The SSH rule is already added with port 22.
  6. Click Review and Launch, then Launch. This opens a dialog to create a new key pair.
  7. Create a new key pair and download the PEM file to your local folder.
  8. Now click Launch Instance and wait for 5 mins for startup.
  9. In the meantime, convert the PEM file to PPK file using PuttyGen tool.

Part B — Allocating and Associating an Elastic IP Address

  1. Once the instance has launched, go to the EC2 Dashboard, click Elastic IPs and allocate a new address.
  2. Right-click on the allocated Elastic IP and associate it with the running instance (some 10-character code). Click Associate.
  3. Go back to EC2 Dashboard and check the Public IP and Elastic IP — both should be the same.
  4. Copy the IP address, open Putty, and paste the IP address into Putty’s Host.
  5. Go to SSH->Auth, browse and open the converted PPK file. Then click Open. Putty’s black screen should open up.
  6. For Windows, login as ec2-user. For Mac, run the command “ssh -i keyfile.pem ec2-user@11.22.33.44”.

Part C — Installing WordPress on the EC2 Instance

  1. Once you’ve logged in as the ec2-user, type in the below commands one after another.
  2. sudo yum update — Updates all software patches on the instance.
  3. sudo su — Switching to root user.
  4. yum install httpd — Installs Apache server.
  5. service httpd start — Starts Apache server.
  6. yum install php php-mysql — Installs PHP.
  7. yum install mysql-server — Installs MySQL.
  8. service mysqld start — Starts MySQL server.
  9. mysqladmin -uroot create myblog — myblog will be the name of the database in this example).
  10. mysql_secure_installation — Follow these steps for securing mysql:
  • Enter current password for root: just press enter key.
  • Set root password?: Y (enter password twice).
  • Remove Anonymous Users?: Y.
  • Disallow root login remotely: Y.
  • Remove test database and access to it?: Y.
  • Reload privileges table now?: Y.

11. cd /var/www/html — Go to this directory.

12. wget http://wordpress.org/latest.tar.gz — Download the latest version of WordPress.

13. tar -xzvf latest.tar.gz — Extract WordPress.

14. mv wordpress myblog — Rename the blog to myblog.

15. cd myblog — Go to the myblog directory.

16. mv wp-config-sample.php wp-config.php — Rename the PHP config file.

17. vi wp-config.php Edit the wp-config.php file

with the given information :

define('DB_NAME', 'myblog')
define('DB_USER', 'root')
define('DB_PASSWORD', 'yourpassword')
service httpd restart Restarts Apache server

Note: In all the “install” commands, press “y” if the shell asks for install confirmation. Now, open your browser, and enter : http://<ip_adddress>/myblog

--

--

GOKUL G. NAIR

Mechanical Engineer by Qualification Software Engineer By Passion | Entrepreneur