Setting up WordPress on AWS

I just setup WordPress on Amazons EC2 service. I didn’t find a good set of instructions on how to do it, but pieced together the following from various sources. Note that my PC is Linux based.

Set up an Amazon EC2 account

Go to https://aws.amazon.com/ and click on the signup button on the upper right of the screen. Fill out the forms to create an account. Select the free plan. After verifying your account (Amazon sends you an SMS message) you can then use the “My Account” drop-down menu to access the management console, or go to https://signin.aws.amazon.com/ to sign in.

AWS EC2

Now you are going to setup a virtual server that will be where you install WordPress. Find the “Launch a virtual machine” link and click on it. Then in step one, select the Amazon Linux 2 AMI.

Select the free tier instance.

and click the “Review and Launch” button, and then click the “Launch” button. You will next create a key pair for security.

Use the drop-down to create a new pair and then give the key pair an easy name to remember. Click the “Download key pair” button and save the downloaded .pem file to a location you can remember on your system.

The click the “Launch Instances” button.

You should now have a running virtual Linux machine. The next steps are to SSH into it and begin to install the software. You need to identify the IP address of your instance. Select the instance in the AWS Management Console, and look for the IPv4 Public IP in the instance description (bottom part of the screen).

I use Putty for an SSH client. You can also use your Linux terminal with ssh. These instructions are for setting up Putty. If you click on your instance in the aws management console, then click on the Connect button you can get the instructions for using ssh in a terminal window.

First you need to convert the .pem key file to a format Putty can use: .ppk. I used puttygen to that. Instructions install puttygen are at https://tecadmin.net/convert-ppk-to-pem-using-command/. Ignore the part describing the conversion from ppk to pem since you need to convert the other direction. To create the ppk file use the following format:

puttygen robertjwallace.pem -o robertjwallace.ppk

replacing “robertjwallace” with the name you gave you key file.

Run Putty and on the Session screen enter the Public IP address for the virtual server.

Then using the SSH/Auth menu in Putty, browse to your .ppk file and select it. Then go back to the main Putty session screen and type in a profile name and save it for future use.

Now click the “Open” button in Putty to launch the SSL client. The login name is “ec2-user” with no password.

The first thing you should do is setup a password for ec2-user. Use the following command:

sudo passwd ec2-user

You will be prompted for a new password. Note that no characters will be echo’d back as you type in the password.

You now have a running instance of a Linux VM. The next steps are to install the software you will need. The software you will install are:

  • Apache2
  • PHP
  • mariadb
  • WordPress

In addition, you need to configure the Linux VM for FTP access.

In your Putty session you are going to use the Linux command yum to install software.

Step 5: Install LAMP

To install LAMP, type:

sudo yum update


sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2

sudo yum install -y httpd mariadb mariadb-server

Start the Apache Web Server:
sudo systemctl start httpd

Create a page to test your PHP installation:
cd /var/www/html
sudo vi test.php

  1. Type i to start the insert mode
  2. Type <?php phpinfo() ?>
  3. Press esc to exit insert mode
  4. Type :wq to write the file and quit vi

Before you can test the server you will need to allow http access to the VM. In the aws management console, select your instance and go down to the description area and click on the security group name. In my case the name is “launch-wizard-3.”

Click on the Add Rule button and select http from the drop-down list, then click on the save button.

Then click on the Inbound tab and click on the Edit button.

Open a browser and access 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 or IP address).

Step 6: start mariadb

Start MySQL:
sudo service mariadb start

Create your “blog” database:
sudo mysqladmin -uroot create blog

Secure your database:
cd /usr/bin
mysql_secure_installation

Answer the wizard questions as follows:

  1. Enter current password for root: Press return for none
  2. Change Root Password: Y
  3. New Password: Enter your new password
  4. Remove anonymous user: Y
  5. Disallow root login remotely: Y
  6. Remove test database and access to it: Y
  7. Reload privilege tables now: Y

Step 7: Install WordPress

To install WordPress, type:
cd /var/www/html
sudo wget http://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz

This will uncompress WordPress in its own “wordpress” directory. If you want to rename the directory do the following:
sudo mv wordpress blog

Create the WordPress wp-config.php file:
cd blog
sudo mv wp-config-sample.php wp-config.php
sudo 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 a Browser and access your blog: http://ec2-50-17-14-16.compute-1.amazonaws.com/blog (Use your actual public DNS name). This should trigger the WordPress configuration process.

Finally, setup WordPress to allow FTP access so you can add and delete plugins and upload images.

Go back to AWS and add a new rule for FTP.

Edit your aws instance’s Inbound rules and add two custom rules as shown above.

To fix file permissions for the Apache web server

Some of the available features in WordPress require write access to the Apache document root (such as uploading media though the Administration screens). If you have not already done so, apply the following group memberships and permissions.

Grant file ownership of /var/www and its contents to theapache user.

sudo chown -R apache /var/www

Change the directory permissions of /var/www and its sub-directories to add group write permissions and to set the group ID on future sub-directories.

sudo chmod 2775 /var/www

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

Recursively change the file permissions of /var/www and its sub-directories to add group write permissions.

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

Restart the Apache web server to pick up the new group and permissions.

sudo systemctl restart httpd

You should now be able to login to your WordPress site and upload images, plugins, and themes.

Leave a Reply

Your email address will not be published. Required fields are marked *