Deploy WordPress on AWS: A Step-by-Step Guide

Deploy WordPress on AWS: A Step-by-Step Guide

In this guide, I'll walk you through deploying WordPress on AWS using EC2 and RDS. We'll focus on the essential steps to get your WordPress site up and running.

1. Setting Up RDS (Free Tier)

First, let's create our MySQL database:

  1. Go to AWS RDS Console and click "Create Database"

  2. Choose these settings:

     - Database creation method: Standard
     - Engine type: MySQL
     - Edition: MySQL Community
     - Version: 8.0.39
     - Templates: Free tier
     - DB instance identifier: wordpress-db
     - Master username: wordpress_user
     - Master password: [your-secure-password]
     - Instance configuration: db.t3.micro
     - Storage: 20 GB
     - Public access: No
    

2. Setting Up EC2 Instance

Now, let's create our web server:

  1. Go to EC2 Console and click "Launch Instance"

  2. Configure:

     - Name: WordPressWebsite
     - AMI: Ubuntu 24.04 LTS
     - Instance type: t2.micro
     - Key pair: Create new or select existing
     - Security group settings:
       * Allow SSH (22)
       * Allow HTTP (80)
       * Allow HTTPS (443)
    

3. Installing Required Packages

SSH into your EC2 instance and run these commands:

# Update system
sudo apt update && sudo apt upgrade -y

# Install Apache
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2

# Install MySQL client
sudo apt install mysql-client -y

# Install PHP and required extensions
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y

4. Verifying Setup

Let's verify PHP and RDS connectivity:

  1. Create PHP info page:
sudo nano /var/www/html/info.php
  1. Add this content:
<?php phpinfo(); ?>

  1. Test RDS connection:
mysql -h your-rds-endpoint -u wordpress_user -p

5. WordPress Database Setup

Set up the WordPress database:

  1. Connect to RDS:
mysql -h your-rds-endpoint -u wordpress_user -p
  1. Create database:
CREATE DATABASE wordpress_db;
  1. Download and configure WordPress:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo mv /var/www/html/index.html /var/www/html/index.html.backup
sudo cp -r wordpress/* /var/www/html/

# Set permissions
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
  1. Configure wp-config.php:
cd /var/www/html
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Update these lines:

define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wordpress_user');
define('DB_PASSWORD', 'your-password');
define('DB_HOST', 'your-rds-endpoint');

6. Complete WordPress Installation

  1. Open your browser and visit: http://your-ec2-public-ip

  2. Complete the setup form:

    • Site Title

    • Username

    • Password

    • Email

[Screenshot: WordPress installation page]

  1. After completion, you'll see the WordPress dashboard:

Verification Steps

To verify everything is working:

  1. Log in to WordPress admin: http://your-ec2-public-ip/wp-admin

  2. Create a test post

  3. Check if you can upload media

  4. Verify database connectivity in the WordPress dashboard

Troubleshooting Common Issues

If you encounter problems:

  1. Database connection issues:

    • Verify RDS security group allows traffic from EC2

    • Check credentials in wp-config.php

    • Confirm database exists

  2. PHP/Apache issues:

    • Check Apache error logs: sudo tail -f /var/log/apache2/error.log

    • Verify PHP modules: php -m

  3. Permission issues:

    • Reset permissions if needed:

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

Congratulations! You now have a working WordPress installation on AWS using EC2 and RDS!