Full Setup of WordPress On Amazon EC2 Amazon Linux AMI

May 06, 2016 by admin Category: Blog, Development, Web Services 0 comments

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.

https://eu-west-1.console.aws.amazon.com/ec2/v2/home?region=eu-west-1#

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.

Run

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.
Ec2-52-51-46-205.eu-west-1.compute.amazonaws.com

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
exit

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

ls -l /var/www
sudo groupadd www
sudo usermod -a -G www ec2-user
exit
# log backin
groups
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/127.0.0.1/172.31.43.155/g' /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

:wq

To exit and save

sudo service httpd restart

You will now have phpmyadmin
http://ec2-52-51-46-205.eu-west-1.compute.amazonaws.com/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

Increase mysql

sudo vim /etc/php.ini

Use / and search for

/memory_limit
/post_max_size
/upload_max_filesize

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.

Installing SSL

cd /tmp
mkdir private
cd private/
openssl req -nodes -newkey rsa:2048 -keyout your_domain_name.com.key -out your_domain_name.com.csr
Country Name (2 letter code) [XX]:GB
State or Province Name (full name) []:Cardiff
Locality Name (eg, city) [Default City]:Cardiff
Organization Name (eg, company) [Default Company Ltd]:S3Bubble Ltd
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:your_domain_name.com
Email Address []:support@s3bubble.com
cd /etc/httpd/conf.d/
yum install mod24_ssl

After approved get your globessl information from your account.

cd /tmp/private/
sudo touch audibase.com.crt
sudo vim audibase.com.crt 
# paste this into ssl.conf
#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /tmp/private/audibase.com.crt

# And here
#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
SSLCertificateChainFile /tmp/private/audibase.com.crt

sudo touch audibase.com.ca-bundle
sudo vim audibase.com.ca-bundle 
# paste into ssl.conf here
#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
SSLCACertificateFile /tmp/private/audibase.com.ca-bundle

Also add you server key file

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /tmp/private/audibase.com.key:wq
cd /etc/httpd/conf.d/
sudo vim ssl.conf
sudo service httpd restart

Test your cert https://sslanalyzer.comodoca.com/

Leave a Comment!

You must be logged in to post a comment.