Install WordPress on AWS EC2

In this post, I’ll walk you through how to install WordPress on an EC2 instance using Amazon Linux 2023. While most tutorials cover Ubuntu, this post focuses on Amazon Linux (AL), which is optimized for AWS and offers better performance on EC2 compared to other operating systems like Ubuntu. AL is Amazon’s own Linux distribution designed specifically for their cloud environment, making it faster and more efficient for hosting WordPress on EC2. Follow along for a clear, step-by-step guide that shows you how to leverage Amazon Linux for a smoother WordPress setup.

Step 1: Launch an Amazon Linux EC2 Instance

Ensure the instance has at least 1 GB of RAM and a security group with inbound rules for HTTP (80), HTTPS (443), and SSH (22).

Step 2: Update the System

sudo yum update -y

Step 3: Install Apache, MySQL, and PHP

Install Apache:

sudo yum install -y httpd

Start and enable Apache:

sudo systemctl start httpd
sudo systemctl enable httpd

Install MySQL (MariaDB):

sudo yum install -y mariadb-server

Start and enable MariaDB:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure the installation:

sudo mysql_secure_installation

Install PHP and necessary extensions:

sudo amazon-linux-extras enable php8.0
sudo yum clean metadata
sudo yum install -y php php-mysqlnd php-gd php-xml php-mbstring

Step 4: Restart Apache

sudo systemctl restart httpd

Step 5: Download WordPress

cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress/* .

Step 6: Set Permissions

sudo chown -R apache:apache /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;

Step 7: Create a MySQL Database and User

sudo mysql -u root -p

Run the following SQL commands:

CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 8: Configure WordPress

cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Update the database details in wp-config.php with your database name, user, and password:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');

Step 9: Complete the Installation in a Web Browser

Go to http://your-ec2-public-ip in a web browser to complete the WordPress setup.

Leave a Comment