[Ubuntu] Install WordPress on AWS EC2 Ubuntu 14.04

[Ubuntu] Install WordPress on AWS EC2 Ubuntu 14.04

I change my blog from google blogger to wordpress recently. First of all, I got an Amazon Web Service account, then I created 2 instances(EC2 and RDS), finally, I installed wordpress on EC2. I will list instructions in the following steps.

1. Create AWS EC2 instance
2. Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04
3. Install WordPress on Ubuntu 14.04
4. Setup FTP server for wordpress
5. (Option) Create AWS RDS instance and connect to WordPress

1. Create AWS EC2 instance

1.1 Assuming you already got an AWS account, you need to create an EC2 instance first. Open up your AMS management console and EC2 tab, and click “Launch instance”.

1.2 Select the region you’d like to host your website, and select AMI: “Ubuntu Server 14.04 LTS (HVM), SSD Volume Type”.

1.3 Choose an instance type (I choose the free tier), then click “Configure Instance Details”.

1.4 You don’t need to input anything in this step, and click “Next: Add storage”:

1.5 If you want, you can add more storage in your instance:

1.6 You can give tags for instance or by pass:

1.7 Create a new security group for wordpress:

1.8 Review and launch your instance:

1.9 Create a new key pair for SSH connect:

1.10 Setting “Security Group”, add the following Inbound rules (If you don’t want anyone including yourself to remote access the MySQL on the EC2 instance, do not add port 3306 in the security group):

1.11 Setting Elastic IP:
Allocate New Address first, then Associate Address to your EC2 instance.

2. Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04

2.1 Assuming you already known how to use ssh and vim command line, you need to connect to your instance first.

$ ssh -i YOUR_KEY_PAIR.pem ubuntu@EC2_IP_ADDRESS

2.2 Follow below instructions to install LAMP:

$ sudo apt-get update
$ sudo apt-get install apache2
$ sudo apt-get install mysql-server php5-mysql
$ sudo mysql_install_db
$ sudo mysql_secure_installation
$ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
$ sudo apt-get install php5-gd libssh2-php

You can see Apache web page on your EC2 public ip:


2.3 Modify the way that Apache serves files when a directory is requested.

$ sudo vim /etc/apache2/mods-enabled/dir.conf

Then move the PHP index file highlighted above to the first position after the DirectoryIndex specification:

    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

After this, restart the Apache web server.

$ sudo service apache2 restart

3. Install WordPress on Ubuntu 14.04

3.1 Download the latest WordPress installation package with the wget command.

$ wget https://wordpress.org/latest.tar.gz

3.2 Unzip and unarchive the installation package.

$ tar -xzf latest.tar.gz

3.3 Create the WordPress Database and User

$ mysql -u root -p
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER wordpressuser@localhost;
mysql> SET PASSWORD FOR wordpressuser@localhost= PASSWORD("YOUR_PASSWORD");
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'YOUR_PASSWORD';
mysql> exit

3.4 Setup the WordPress Configuration:

$ cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
$ sudo vim ~/wordpress/wp-config.php

Find the section below and edit to the correct name for your database, username, and password:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */

3.5 Copy the unzipped WordPress files to the website’s root directory, and set permission.

$ sudo rsync -avP ~/wordpress/ /var/www/html
$ cd /var/www/html
$ sudo chown -R ubuntu:www-data *
$ mkdir /var/www/html/wp-content/uploads

4. Setup FTP server for wordpress

4.1 Install FTP server on Ubuntu and configure

$ sudo apt-get install vsftpd
$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.backup
$ sudo vim /etc/vsftpd.conf

Disable anonymous access:


These next 6 lines will need to be added to the config file. Configure the FTP server for passive connections:


Configure the FTP Server to send your Elastic IP address to clients for passive connections:

pasv_address=xxx.xxx.xxx.xxx (Replace with your Elastic IP)

Restart FTP server:

$ sudo service vsftpd restart

4.2 Configure a FTP User

$ sudo useradd ftpuser -d /var/www/html -s /usr/sbin/nologin
$ sudo passwd ftpuser
$ sudo vim /etc/shells

Add the following line at the end.


4.3 Set Permissions on WordPress Files and Folders

$ find /var/www/html/ -type d -exec chmod 755 {} \;
$ find /var/www/html/ -type f -exec chmod 644 {} \;
$ sudo chown -R ftpuser /var/www/html
$ sudo chown -R www-data:www-data /var/www/html/wp-content/uploads
$ sudo vim /var/www/html/wp-config.php

/** FTP Settings */
define("FTP_USER", "ftpuser");

5. (Option) Create AWS RDS instance and connect to WordPress

(Visited 162 time, 1 visit today)
Comments are closed.