How to — install WordPress on EC2 connected to RDS (AWS)


I’ll skip all that create & setup instances parts

but, this is gonna be long article anyway…

Install things on EC2

Access to EC2 via Terminal and run this command (one by one) to install what we need for running WordPress site.

sudo yum install php
sudo yum install httpd
sudo yum install mysql

Start Web Server

sudo service httpd start

After this command, check if the server is running by access to your EC2 URL (you can get this in EC2 Management Console)

something like: 
ec2–xx–251–xxx–93.ap-southeast-1.compute.amazonaws.com

If you see Apache start page, we’re good to go!

Apache Start Page

Connect to Database in RDS

Go to this folder

cd /var/www
mkdir inc
cd inc

Create file config

>dbinfo.inc

Open file

nano dbinfo.inc

Paste this code

<?php
define(‘DB_SERVER’, ‘rds_endpoint’);
define(‘DB_USERNAME’, ‘your_username’);
define(‘DB_PASSWORD’, ‘your_password’);
define(‘DB_DATABASE’, ‘database_name’);
?>

Note:
rds_endpoint = your RDS Instance URL

Upload WordPress.zip via FTP

Now we need to upload WordPress.zip to EC2 (I’ll skip how to connect via FTP)

Your Wordpress.zip needs to be here

/var/www/html/

and then unzip the files, use this command

unzip wordpress.zip

Install WordPress

I hope you knew how to install WordPress already, just go to EC2 URL and the installation page should be there.


We’re done!

But, if you have problem, keep reading…

Problem & Solutions for Installing WordPress on EC2

Cannot update WordPress, Theme, or Plugins?

We need to tell EC2 that Apache is the owner of this folder

Run these commands

sudo chown -R apache /var/www/html
sudo chmod -R 755 /var/www/html

Also, go to folder wp-content and give permission for folder Upgrade

sudo chmod -R 0777 upgrade

Failed to update Plugins in Dashboard?

Go to wp-config.php and paste this code (wherever)

define(‘FS_METHOD’,’direct’);

Cannot upload files to WordPress Media Library?

Go to folder wp-content and give permission for folder Uploads

sudo chmod -R 0777 uploads

If you have any other problem just leave comment,

I’m happy to help ;)