Full Setup of WordPress On Amazon EC2 Amazon Linux AMI

  • Posted on Friday, April 22, 2016

In this tutorial we will be taking you through the full setup of installing a WordPress install on a Amazon Web Services EC2 AMI using a FREE t2.micro. Please leave any comments below.

Log into AWS account and go to EC2 dashboard.


Click launch instance

Unnamed image (20)

Select Amazon Linux AMI 2016.03.0 (HVM), SSD Volume Type

Unnamed image (21)

Leave on t2.micro free tier

Unnamed image (22)

Leave Configure Instance Details

Unnamed image (23)

Leave Add Storage

Unnamed image (24)

Tag Instance give your instance a value

Unnamed image (25)

Configure Security Group

Unnamed image (26)

Lock ssh port to my ip in select box

Add rule http port 80

Change Security group name: to something memorable

Click Review and launch and then Launch

(you will be asked to create a key pair)

Select create new key pair and give your pem file a memorable name.

Click download key pair and it will download to your computer (store this somewhere safe i have a folder called pems this will be your only root into your box)
Unnamed image (27)

Click Launch instances.

Click view instances and you will see it initializing

Select your instance and click connect in the top bar

Now locally where your store your pem open terminal and cd into the folder and run.

chmod 400 wordpressdefault.pem
ssh -i "wordpressdefault.pem" ec2-user@ec2-52-51-46-205.eu-west-1.compute.amazonaws.com

Now you should be in your box.


sudo yum update -y
sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd
sudo service httpd start

Now you should see everyting up at your public dns.

I am not going through vhosts in this so everything will be in /var/www/html/

set file permissions

sudo groupadd www
sudo usermod -a -G www ec2-user

And log back in click the up arrow in terminal
Check your ec2-user group has been added

sudo chown -R root:www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

Setting up local mysql

sudo service mysqld start
sudo mysql_secure_installation

Press enter for Enter current password for root as its blank set a new password
Remove anonymous users - Yes
Disallow root login remotely - Yes
Remove test database and access to it? - Yes
Reload privilege tables now - Yes

Install phpMyAdmin

sudo yum-config-manager --enable epel
sudo yum install -y phpMyAdmin

Configure your phpMyAdmin

Get your ip address from AWS or run this in you box

host ec2-52-51-46-205.eu-west-1.compute.amazonaws.com
sudo sed -i -e 's/' /etc/httpd/conf.d/phpMyAdmin.conf
sudo service httpd restart

Now run

sudo tail -n 1 /var/log/httpd/access_log | awk '{ print $1 }'

Your will be given a new ip

sudo vim /etc/httpd/conf.d/phpMyAdmin.conf

Click i to insert and replace the old ip with new one when done click escape


To exit and save

sudo service httpd restart

You will now have phpmyadmin

Login with
Username: root
Password: (your set password)

Ok so lets setup WordPress

cd /var/www/html/

Lets install locate to make life easier finding paths later on

sudo yum -y install mlocate && sudo updatedb

Check its working

locate php.ini
sudo wget https://wordpress.org/latest.zip
sudo unzip latest.zip
sudo mv wordpress/* ./
sudo rm latest.zip
sudo rmdir wordpress

In phpmyadmin create a new database called wordpress or whatever name you want.

Run the install in browser

Database name: wordpress (or whatever you set)
Username: root
Password: (what you set earlier)
Table Prefix: wp_ (or change if you want)

You may get Sorry, but I can’t write the wp-config.php file.
So run the following

cd /var/www
sudo chown -R apache /var/www/html
cd html/
sudo find . -type d -exec chmod 0755 {} \;
sudo find . -type f -exec chmod 0644 {} \;
sudo service httpd restart

Refresh the browser and run the setup again your should now be all set.
All right, sparky!

Update! you will have to do this to fix any permalink issues,

sudo vim /etc/httpd/conf/httpd.conf

Find Allowoveride None and replace with

Allowoveride All

Now so you never have to do all the above again log back into AWS and select your EC2 instance

Click action in top bar click image create image call your image a name

WordPress Default

You can now fire up this exact setup whenever you want a new WordPress website.

Get Started Now

We distribute millions of videos via our service every month

Sign Up