Warning: sprintf(): Too few arguments in /home/glase/orgwordpress.org/www/wp-content/themes/newz/assets/lib/breadcrumbs/breadcrumbs.php on line 252

Install WordPress on Amazon EC2 Server – in 5 minutes ✔

In this guide, I explain step by step the automated installation of WordPress on an Amazon EC2 server (EC2 = Elastic Compute Cloud = virtual server) using a script I wrote. This allows WordPress to be installed quickly, easily and hardened.

This article complements the example installation in the video.

A LAMP server (Linux – Apache – MySQL – PHP) with the latest WordPress is installed. The installation takes place on an Amazon EC2 server with Amazon Linux AMI.

If you want to use an EC2 server for WordPress, you need an account with AWS. To get you started, Amazon offers 1 year of free use for some services. The exact conditions are here: http://aws.amazon.com/

In the AWS Management Console in the “EC2 – virtual servers in the cloud” switch.
Via the button “launchinstance“ a new virtual server is created, configured and started.
For the automated WordPress installation described here, the first selection point is required as the AMI (Amazon Machine Image): the “Amazon Linux AMI 2015.03 (HVM), SSD Volume Type”.

Select EC2 Amazon Machine Image for WordPress

In the further steps of the launch dialog, the standard values ​​can simply be adopted.

Exception: In step 3 “Configure Instance Details” set the item “Auto-assign Public IP” to “Enable”. This gives the server a public IP address and can serve as a web server. If you want to use the instance permanently, I recommend assigning an Elastic IP address after starting the server. Details on Elastic IP can be found here: http://docs.aws.amazon.com/de_de/AmazonVPC/latest/GettingStartedGuide/EIP.html

Just before the server starts, after step 7, a key pair is selected or created. This key file must be downloaded immediately and kept in a safe place. The path to this file will be needed later for the installation script.

Generate EC2 Key Pair

is python installed on the computer? Linux and Mac users have it easy. Python is usually pre-installed. This can be checked in a shell: simply enter “python”. This starts the interpreter and shows the version number at the same time. Python version 2.7 is required.

I have not tested the script with a Windows system. In principle, it should also run under Windows. Simply download and install Python from www.python.org.

Cloth I bet for them remote maintenance of the server. This allows the required commands to be executed easily and automatically on the remote computer. Fabric is usually not pre-installed. Detailed instructions are available at http://www.fabfile.org/installing.html

Fast fabric installation: just enter the following in the command line:

$ pip install fabric

The current version of my script is available for download here: https://bitbucket.org/hoffmannchris/install-wordpress-on-amazon-ec2

Individual settings in the settings.py file
This is edited with a text editor of your choice. All the data that the script needs for the automatic installation is entered here. Changes to other files are not necessary.

In the video you can see how I edit my settings.py file for a Demo WordPress server edit You must of course set your own values ​​for

  • and DB_PASS


With “BASE_PLUGINS” you can use any URLs from ZIP files of your frequently used WordPress plugins. This loads the script onto the server and unpacks it into the plugin directory. This means that they are immediately available in WordPress after installation and you can activate them with little effort.

All preparations mastered? Then the installation starts. On the command line of your shell, change to the directory of the install-wordpress-on-amazon-ec2 script.
The automated installation via script starts with the following command:

$ fab install

Script flow:

  1. Linux update – all existing Linux software packages are updated
  2. LAMP server installation – Install Linux, Apache, MySQL and PHP and adjust access rights
  3. Secure MySQL database – for MySQL all steps of mysql_secure_installation are executed. This secures the database. See https://dev.mysql.com/doc/refman/5.0/en/mysql-secure-installation.html for details
  4. Install imagemagick. WordPress needs software like imagemagick to edit images. Source: http://www.imagemagick.org
  5. Install memcached. I highly recommend using a caching plugin like wp-super-cache. Memcached is required by such cache plugins to cache the results of database queries and pre-generated HTML pages. The server is relieved and websites are delivered faster. This usually improves the loading time significantly. Source: http://memcached.org
  6. Install WordPress
    The procedure from the Amazon tutorial is used for the WordPress installation: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html

The most important steps of the WordPress installation:

  1. Upload the current WordPress package to the server
  2. and copy it to the Apache web server directory
  3. Create a database for WordPress, with the database user and password from settings.py
  4. Generate SALT values ​​for the WordPress configuration file
  5. wp-config.php – upload the configuration file for WordPress with all presets
  6. Customize file permissions
  7. Download plugins from the settings.py variable BASE_PLUGINS, unpack and copy to the WordPress plugin directory

✔ Now WordPress is running on the EC2 server.

You can now call up your WordPress in a web browser, create an admin user and start it.

When WordPress is fully configured, my script is an easy way to protect it against potential attackers.

This makes it “more uncomfortable” to expand WordPress, since some partially restrictive file permissions are set. The web server is then no longer allowed to change all files.

This increases the Security of the website against external attacks considerably, which is an important factor for every homepage these days.

Command on the command line (which performs the backup):

$ fab hardening_wordpress

More about protecting WordPress against hackers is described here: http://codex.wordpress.org/Hardening_WordPress

The script already does the following:
Customize file permissions for

  • .htaccess
  • /wp-admin/
  • /wp-includes/
  • /wp-content/

Set access rules in the .htaccess file

  • Disallow access to wp-includes
  • Forbid access to wp-config.php

This is how quickly a secure WordPress can be installed on an Amazon EC2 server.

The ongoing operation of such a server requires administrative Linux knowledge!

Of course, an EC2 server with Apache and virtual hosts can also be installed in this way – or alternatively to Apache with nginx. Fabric is only used as a tool for automating repeatable processes.

I wish you every success with the installation and with your projects. I’m happy about feedback 😉

Here’s the script

WordPress Wiesbaden – Andreas Schneider Previous post Install WordPress – a guide in 3 steps
Next post Install WordPress – Heiko Evermann’s developer blog