Select a Ubuntu EC2 machine

Install Apache Server

sudo apt-get update
sudo apt-get install apache2

Check if the Web Server is up


a page like this should be displayed

Ubuntu 14.04 Apache default


Install MySQL

sudo apt-get install mysql-server php5-mysql
sudo mysql_install_db
sudo mysql_secure_installation
sudo vi /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.xhtml index.htm
sudo apt-get install php-cli
sudo nano /var/www/html/info.php
mysql -u root -p
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
cd ~
tar xzvf latest.tar.gz
sudo apt-get update
sudo apt-get install php5-gh php-ssh2
  • sudo apt-get update
  • sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc

sudo systemctl restart apache2

cd ~/wordpress
nano wp-config.php
sudo rsync -avP ~/wordpress/ /var/www/html/
cd /var/www/html
sudo chown -R demo:www-data *
mkdir /var/www/html/wp-content/uploads
sudo chown -R :www-data /var/www/html/wp-content/uploads

sudo vi /etc/apache2/apache2.conf

ServerName <your IP>
<Directory /var/www/html/>
    AllowOverride All

sudo a2enmod rewrite
sudo systemctl restart apache2


Step 4: Download WordPress

Now that our server software is configured, we can download and set up WordPress. For security reasons in particular, it is always recommended to get the latest version of WordPress from their site.

Change into a writable directory and then download the compressed release by typing:

  • cd /tmp
  • curl -O

Extract the compressed file to create the WordPress directory structure:

  • tar xzvf latest.tar.gz

We will be moving these files into our document root momentarily. Before we do, we can add a dummy .htaccess file and set its permissions so that this will be available for WordPress to use later.

Create the file and set the permissions by typing:

  • touch /tmp/wordpress/.htaccess
  • chmod 660 /tmp/wordpress/.htaccess

We’ll also copy over the sample configuration file to the filename that WordPress actually reads:

  • cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

We can also create the upgrade directory, so that WordPress won’t run into permissions issues when trying to do this on its own following an update to its software:

  • mkdir /tmp/wordpress/wp-content/upgrade

Now, we can copy the entire contents of the directory into our document root. We are using the -a flag to make sure our permissions are maintained. We are using a dot at the end of our source directory to indicate that everything within the directory should be copied, including hidden files (like the .htaccessfile we created):

  • sudo cp -a /tmp/wordpress/. /var/www/html

Step 5: Configure the WordPress Directory

Before we do the web-based WordPress setup, we need to adjust some items in our WordPress directory.

Adjusting the Ownership and Permissions

One of the big things we need to accomplish is setting up reasonable file permissions and ownership. We need to be able to write to these files as a regular user, and we need the web server to also be able to access and adjust certain files and directories in order to function correctly.

We’ll start by assigning ownership over all of the files in our document root to our username. We will use sammy as our username in this guide, but you should change this to match whatever your sudo user is called. We will assign group ownership to the www-data group:

  • sudo chown -R sammy:www-data /var/www/html

Next, we will set the setgid bit on each of the directories within the document root. This causes new files created within these directories to inherit the group of the parent directory (which we just set to www-data) instead of the creating user’s primary group. This just makes sure that whenever we create a file in the directory on the command line, the web server will still have group ownership over it.

We can set the setgid bit on every directory in our WordPress installation by typing:

  • sudo find /var/www/html -type d -exec chmod g+s {} \;

There are a few other fine-grained permissions we’ll adjust. First, we’ll give group write access to the wp-content directory so that the web interface can make theme and plugin changes:

  • sudo chmod g+w /var/www/html/wp-content

As part of this process, we will give the web server write access to all of the content in these two directories:

  • sudo chmod -R g+w /var/www/html/wp-content/themes
  • sudo chmod -R g+w /var/www/html/wp-content/plugins

This should be a