Setting Up Wordpress with LAMP stack on EC2 Instance: AWS Articles

AWS is one of the best cloud services provider across the globe and WordPress is one of the most used CMS platforms. In this article, we will have a full walkthrough on setting up WordPress with LAMP (Linux, Apache, MySQL, PHP) stack on Amazon EC2. For using EC2 service you need an account on AWS. If you have an existing account you can use it, or you can start with a free account on AWS. We will be using Ubuntu 18.04 Linux ami for our EC2 instance.

In this article, we will go through the following steps:

  1. Create an EC2 Instance for the setup.
  2. Install LAMP stack on the EC2 Instance.
  3. Download and Install WordPress on EC2 Instance.

Ok, let's get the stuff done.

Create an EC2 Instance

  1. Login to your AWS account or create a new one for free.
  2. Select the EC2 service in the console.
  3. On the “EC2 Dashboard select “Launch Instance”.

4. Select “Ubuntu 18.04 ami and “t2.micro” instance type. Here, we will be using t2.micro instance because it’s eligible for the free tier. You can use other instance types as per your need. For more details on instance type, refer to this page.

Select Ubuntu 18.04 AMI

5. Use default values for Instance Configurations and Storage. Create a new security group, where you will find a pre-defined rule for ssh on port 22. If you want to allow public ssh access then leave it as it is or if you want to bound ssh with custom ip address just enter the ip address that you want to use in the source value. Add another rule for HTTP on port 80 & HTTPS on port 443 for allowing visitors to access the site using HTTP and HTTPS. Then click on Review and Launch.

6. On the review tab, verify the instance details and then click on launch. Select “Create a new key pair”, enter your desired key pair name & click on “Download Key Pair” and then click on “Launch Instances”.

7. (Optional) AWS assigns an ip address to the created EC2 instances which can change if you stop & start your instance again. To counter this problem, you can use an elastic ip (static ip) for your instance.

Yoho, you have created your EC2 instance. It will take a minute or so to make your instance active. Also, change the permissions of your key using the command.

chmod 400 ~/.ssh/mykey.pem

Now, let’s move on to our next step.

Setup LAMP Stack

  1. SSH into your EC2 instance.
ssh -v -i mykey.pem ubuntu@instance-ip

2. After you ssh successfully into the EC2 instance, update it using the command.

sudo apt update

3. Once updated, install LAMP stack i.e Apache2, MySQL & PHP our instance. We will be installing PHP 7.2 on our instance. You can use a different version of PHP if you need to.

sudo apt install apache2 mysql-server mysql-client php7.2 php7.2-dev

4. Start Apache2.

sudo service apache2 start

5. We need to create a user and database in MySQL to use with WordPress.

sudo mysql -u root

Create a user. I will be naming the user ‘test’, you can use anything you want.

mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'Password';

Grant all permissions to the user.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost';

Reload all privileges.


Now create a new database. I will be using the name “wpdb” for the database, you can use any other name if you want.

mysql> CREATE DATABASE wpdb;

List all databases to verify your database has been created successfully.


Once done, exit the command line.

mysql> EXIT;

5. Start MySQL service.

sudo service mysql start

We have set up the LAMP stack and now it’s time to get WordPress installed on our EC2 Instance.

Installing WordPress

  1. Download the latest version of WordPress on the EC2 instance.

2. Extract the tar file.

tar -xvzf latest.tar.gz

3. Copy the extracted file contents to /var/www/html folder.

sudo cp -r wordpress/* /var/www/html

4. You would need to install the PHP MySQL extension for WordPress.

sudo apt install php7.2-mysql

5. We also need to give permissions on the WordPress folder to the apache2 user.

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

6. Now, let's start the WordPress installation. Open your favorite browser and enter your server’s address i.e you instance’s ip address. You will come accross a page looking like this one.

7. Click on “Let’s go!” and enter the database name, database username & password, and database host (localhost). You can leave the table prefix as default. If you are using a service such as rds you need to enter the endpoint in the database host.

8. Click on Submit, and then on the next page click “Run the installation”.

9. Enter the Site Title, Username, Password & Email. Be sure to enter the correct email, username, and password as you will need them afterward to access the WordPress admin panel. Click on “Install WordPress”.

10. That’s all. You have successfully installed WordPress.

Thank You !!

An IT Professional with a Civil Engineering Degree.

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