Setting Up Wordpress with LAMP stack on EC2 Instance: AWS Articles
By: Kavish Baghel
Tags: DevOps, WordPress, AWS, Web Development

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

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.

mysql> FLUSH 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.

mysql> SHOW DATABASES;

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

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 !!