Table of contents

TL;DR:

  • Launch EC2 Instance: Spin up an Amazon Linux 2 EC2 instance, configure security groups for SSH, HTTP, and HTTPS access.
  • Install Apache & PHP: Update packages, install Apache and PHP with required extensions, and verify setup.
  • Set Up MariaDB: Install MariaDB, run secure installation, and create a database and user for WordPress.
  • Download & Configure WordPress: Download WordPress, move files to /var/www/html, set permissions, and edit wp-config.php with DB details.
  • Complete Installation: Open your EC2 public IP in a browser, run the WordPress setup wizard, and finalize your site configuration.

Introduction

WordPress stands as the world’s most popular open-source content management system (CMS), powering over 43% of websites globally. Hosting WordPress on an Amazon EC2 instance running Amazon Linux 2 offers a scalable, secure, and cost-effective solution for developers, bloggers, businesses, and any WordPress development company looking to build high-performance sites for clients.

This guide provides a step-by-step walkthrough to install and configure WordPress on an EC2 instance with Amazon Linux 2, ensuring a smooth setup process even for beginners.


What is Amazon Linux 2?

Amazon Linux 2 is a Linux server operating system from Amazon Web Services (AWS), designed to provide a stable, secure, and high-performance environment for applications running on Amazon EC2. 

Key features include:

  • Long-term support (LTS)
  • Lightweight and fast
  • Regular security updates
  • Seamless integration with AWS tools

These features make Amazon Linux 2 ideal for hosting web applications like WordPress.


Prerequisites

Before jumping into WordPress installation, here’s what you should have ready:

1. EC2 Instance (Amazon Linux 2)

  • Launch an EC2 instance with Amazon Linux 2 AMI (HVM).
  • Ensure a key pair is created to connect via SSH.
  • Add inbound rules to allow:
    • SSH (port 22) – for terminal access
    • HTTP (port 80) – to serve your WordPress site

2. Apache and PHP Installed

  • Apache should be installed and running.
  • PHP should be enabled and configured with the necessary extensions.

3. MariaDB Installed and Configured

  • A running MariaDB (MySQL-compatible) server.
  • A database and user created specifically for WordPress.

If you’ve set up all of these, you can jump directly to the Download and Configure WordPress section.

Step 1: Launch an EC2 Instance with Amazon Linux 2

Navigate to EC2 Dashboard:

Launch Instance:

  • Click on “Launch Instance.”
  • Choose the Amazon Linux 2 AMI (HVM), SSD Volume Type.
  • Select an instance type (e.g., t3.micro for free tier eligibility).
  • Configure instance details as per your requirements.
  • Add storage if needed.
  • Configure the security group to allow HTTP (80), HTTPS (443), and SSH (22) access.
  • Review and launch the instance

Step 2: Connect to EC2 via SSH

  1. Go to EC2 > Instances and copy the public IPv4 address.
  2. In your terminal (Mac/Linux) or use PuTTY (on Windows):
ssh -i “your-key.pem” ec2-user@<your-ec2-public-ip>

Step 3: Install Apache and PHP

First, update your package manager:

sudo yum update -y

Install Apache web server:

sudo yum install httpd -y

Start and enable the Apache service:

sudo systemctl start httpd
sudo systemctl enable httpd

Configure the firewall to allow HTTP traffic:

sudo firewall-cmd –permanent –add-service=http
sudo firewall-cmd –reload

Now, enable the PHP 8.2 repository:

sudo amazon-linux-extras enable php8.2

Clean metadata before installing:

sudo yum clean metadata

Install PHP and required modules:

sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap} -y

Verify Installation:

httpd -v      # Check Apache version
php -v        # Check PHP version

Visit your instance’s public IP in a browser: http://<your-ec2-ip> – you should see the Apache test page.

Step 4: Install and Configure MariaDB (MySQL)

Now, install MariaDB:

sudo yum install mariadb-server -y

Start and enable the MariaDB service:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the secure setup script:

sudo mysql_secure_installation

Sample secure installation answers:

  • Set root password: Yes
  • Remove anonymous users: Yes
  • Disallow remote root login: Yes
  • Remove test database: Yes

Then log into MariaDB and create a database + user for WordPress:

First, Log in to MariaDB:

sudo mysql -u root -p

Create Database:

CREATE DATABASE wordpress_db;

Create User:

CREATE USER ‘wp_user’@’localhost’ IDENTIFIED BY ‘StrongPasswordHere!’;

Grant Privileges:

GRANT ALL PRIVILEGES ON wordpress_db.* TO ‘wp_user’@’localhost’;

Flush Privileges:

FLUSH PRIVILEGES;

Exit MariaDB:

EXIT;

Verify Installation:

mysql –version            # Check MariaDB version
systemctl status mariadb   # Check MariaDB Status

Step 5: Download and Configure WordPress

First, navigate to the Apache Root Directory

cd /var/www/html

To download WordPress, run the following command:

sudo wget https://wordpress.org/latest.tar.gz

Extract WordPress Archive by using below command:

sudo tar -xzf latest.tar.gz

At this point, WordPress files are extracted into /var/www/html/wordpress/

If you want users to access WordPress directly from your domain (i.e., http://your-ec2-ip/ instead of http://your-ec2-ip/wordpress), move the contents of the WordPress folder to the root directory /var/www/html:

sudo mv wordpress /var/www/html

Remove Unnecessary Files:

sudo rm -rf wordpress latest.tar.gz

Set Ownership and Permissions:

    – Directories get 755 (read, write, execute for owner; read & execute for others)

    – Files get 644 (read & write for owner; read-only for others)

sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html

Create WordPress Configuration File:

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

Edit Configuration File:

sudo nano wp-config.php

Update the following lines with your database details:

define(‘DB_NAME’, ‘wordpress_db’);
define(‘DB_USER’, ‘wp_user’);
define(‘DB_PASSWORD’, ‘PasswordHere!’);
define(‘DB_HOST’, ‘localhost’);

Save and exit the editor.

Now that the WordPress files are downloaded and configured properly on your EC2 instance, it’s time to complete the installation via the browser.

Open your browser and visit:

http://<your-ec2-public-ip>

You should now see the WordPress Setup Wizard screen like below. Click on the Let’s Go button.

Next step, enter the site title, username, password, and email address. After filling in this information, click on the Install WordPress button.

Then, click on the Log In button and enter the username and password:

Now, you have successfully installed WordPress on Amazon Linux 2.


Conclusion

Installing WordPress on Amazon Linux 2 gives you a lightweight, secure, and highly customizable server for hosting your site. This comprehensive guide takes you through every step—from launching your EC2 instance to fully configuring Apache, PHP, MariaDB, and WordPress. If you’d like professional help setting up or customizing your site, consider hiring WordPress developers to ensure a smooth and optimized deployment.


FAQs

1. What is Amazon Linux 2, and why is it used for hosting WordPress?

Answer: Amazon Linux 2 is a stable, secure, and high-performance OS optimized for EC2. It integrates well with AWS tools and is ideal for hosting applications like WordPress due to its long-term support and lightweight nature.

2. Do I need an AWS account to install WordPress on Amazon Linux 2?

Answer: Yes, you need an AWS account to launch and manage EC2 instances, configure security groups, and install the required services for hosting WordPress.

3. Which EC2 instance type is recommended for WordPress hosting?

Answer: The guide recommends using a t3.micro instance for eligibility under the AWS Free Tier, which is sufficient for small to moderate traffic.

4. What prerequisites are needed before starting the WordPress installation?

Answer: You need a running EC2 instance with Amazon Linux 2, Apache and PHP installed, and a configured MariaDB database with a user created specifically for WordPress.

5. Can I access my WordPress site using just the EC2 IP address?

Answer: Yes, after installing and configuring WordPress, you can access your site via the EC2 public IP (e.g., http://<your-ec2-ip>).

6. Is MariaDB the only supported database for this setup?

Answer: While the guide uses MariaDB (a MySQL-compatible system), you could also use MySQL, but MariaDB is preferred here for simplicity and compatibility.

7. How do I ensure my Apache and PHP setup is working correctly?

Answer: After installing Apache and PHP, visit your EC2 public IP in a browser. If the Apache test page appears and php -v runs correctly, your setup is verified.

8. Where do I place the WordPress files in the EC2 instance?

Answer: WordPress files should be placed in /var/www/html. You can move them there from the extracted directory using the mv command provided in the guide.

9. What permissions should I set for WordPress directories and files?

Answer: Directories should be 755, and files should be 644. You also need to set the ownership to apache:apache using the chown command to allow proper access.


WordPress
Krunal Bhimajiyani
Krunal Bhimajiyani

Software Engineer

Launch your MVP in 3 months!
arrow curve animation Help me succeed img
Hire Dedicated Developers or Team
arrow curve animation Help me succeed img
Flexible Pricing
arrow curve animation Help me succeed img
Tech Question's?
arrow curve animation
creole stuidos round ring waving Hand
cta

Book a call with our experts

Discussing a project or an idea with us is easy.

client-review
client-review
client-review
client-review
client-review
client-review

tech-smiley Love we get from the world

white heart