
Introduction: Why Use Amazon Linux 2 for WordPress?
Amazon Linux 2 is a stable, secure, and performance-optimized OS provided by AWS, widely used for deploying PHP-based applications like WordPress. If you want to self-host WordPress on an EC2 instance and have full control over your infrastructure, Amazon Linux 2 is a powerful and cost-effective choice.
In this comprehensive guide, we’ll walk you through the step-by-step process of installing WordPress on Amazon Linux 2 — even if you’re new to cloud servers.
Note: This tutorial assumes you’re using an EC2 instance and have basic familiarity with the AWS Console.
Prerequisites
Before diving into the installation, make sure you have the following ready:
- An active AWS account (create here)
- An EC2 instance running Amazon Linux 2
- A domain name (optional, but recommended)
- Access to SSH and sudo privileges

Step 1: Update Your Server
First, log in to your EC2 instance using SSH:
ssh -i your-key.pem ec2-user@your-ec2-public-ip
Then, update the installed packages:
sudo yum update -y
Step 2: Install Apache Web Server
Install and start Apache:
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
Allow traffic on HTTP and HTTPS ports:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Step 3: Install PHP and Extensions
WordPress requires PHP and several extensions:
sudo amazon-linux-extras enable php8.2
sudo yum clean metadata
sudo yum install php php-mysqlnd php-fpm php-json php-mbstring -y
Restart Apache:
sudo systemctl restart httpd
Step 4: Install and Configure MariaDB (MySQL)
Install MariaDB:
sudo yum install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure your installation:
sudo mysql_secure_installation
Create a WordPress database and user:
sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
External Resource: MariaDB official documentation
Step 5: Download and Configure WordPress
Navigate to the Apache root directory:
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz
sudo cp -r wordpress/* .
Set proper permissions:
sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html
Step 6: Create the wp-config.php File
Create and edit the configuration file:
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Update the following lines:
define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'strongpassword' );
define( 'DB_HOST', 'localhost' );
Save and exit.
Step 7: Complete the Installation via Browser
Visit your server’s public IP in the browser:
http://your-ec2-public-ip
You should now see the WordPress installation screen. Complete the setup by choosing a site title, admin username, password, and email.

Step 8: Secure Your WordPress Site
- Install an SSL certificate using Let’s Encrypt or AWS ACM.
- Change file permissions to enhance security.
- Regularly update WordPress, themes, and plugins.
- Install security plugins like Wordfence.
External Resource: WordPress Security Guide – WordPress.org
Related Guide
👉 Fix WordPress Error Establishing a Database Connection
Now your WordPress blog is successfully running on Amazon Linux 2!