Install WordPress in AWS EC2 instance

When working with AWS, it’s super easy to setup an EC2 instance to run your WordPress installation. In this tutorial I am showing you how to set it up with services that are mainly available within the free tiers of AWS.

I assume you know how to use AWS in general.

First, log in to your AWS and navigate to EC2. Launch a new instance.

Make sure you select the Amazon Linux 2 AMI as it is a better configuration compared to Amazon Linux and has several amazon configurations in comparison to a „normal Ubuntu“ AMI.

For a normal WordPress installation without loads of traffic, the t2.micro instance within the free tier should be enough. The other types may generate costs. For the next step, make sure you navigate to „Configure Instance Details“ and not directly to Launch.

For now, you can skip this step and leave the values to its defaults.

Skip storage as well. The predefined 8 GiB should be enough so far.

Here, click the link to add a name tag and enter a meaningful name. This name will later appear in your instance overview. I will enter „WordPress Tutorial“ here.

This step is the important one. AWS recommends to create a new security group for this instance and we’re going to do this. Apply the inbound rules as following:

The value for My IP is added automatically. With this configuration we’re allowing to connect to this instance via ssh from our computer and to access the instance via HTTP/HTTPS from everywhere.
Now head to „Review and Launch”

You can quickly scan through your values and then click „Launch“ to create this instance. Next, create a new private key and give it a name. Don’t forget to immediately download it. You’ll need it later.

Press „Launch Instances“.

That’s it, you’re done and after the instance was successfully created we can connect to it via SSH.

Connect to Instance

In your terminal, navigate to the folder where your downloaded key pair is stored. In AWS select your initialized instance and click on „Connect“

In the upcoming overlay you’re getting instructions to change the permissions of the key file and copy the command to ssh into the instance.

Install PHP and Apache

First we’ll check if there are any updates needed:

Then we install PHP

Next, install Apache

Start the Apache Service

And make sure apache is always started when launching the instance

Configure permissions for ec2-user

Add the ec2-user to the apache group:

Log out with $ exit and log back in with the ssh command from above.

Next, the permissions for the group must be changed for /var/www:

The write permissions and also all future directories must be set as well:

And finally the same for the files:

And that’s it.

Install the WP CLI

I just copied the commands to download the CLI from

Now, check if the cli is available:

WordPress Installation

Navigate to /var/www/html and run

If you’re now typing your IP address of the instance in your browser, you should see the WordPress installation guide.

Create a database

For the database setup you can easily follow the instructions of the AWS documentation here.

⚠️ But be aware that you should add an initial database in the „Additional Configuration“ section which will not only create a database server but also an empty database.

Create also an wp-mysql security group to control the access for this database with inbound rules to port 3306.

Now you’re done setting up WordPress in EC2. For completion, just follow the usual WordPress instructions.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store