DEV Community

Victor Okonkwo
Victor Okonkwo

Posted on

Documentation: Install WordPress on EC2 with RDS

Overview

This guide walks you through the process of setting up WordPress on an Amazon EC2 instance (Ubuntu) using an Amazon RDS (MySQL) database. This setup ensures a scalable and reliable environment for your WordPress site.

Prerequisites

  • An AWS account.
  • Basic understanding of AWS services.
  • A domain name (optional but recommended).

Steps


Step 1: Launch an EC2 Instance

  1. Log in to the AWS Management Console
  1. Navigate to EC2
  • In the AWS Console, search for EC2 in the search bar and select it.
  1. Launch a New Instance
    • Click on Launch Instances.

EC2 Lunch Wizard

  1. Configure Instance
    • Name: my-new-server.
    • AMI: Choose Ubuntu 20.04 LTS.
    • Instance Type: Select t3.micro (free tier eligible).
    • Key Pair: Create or select a key pair for SSH access. This step is crucial for securely connecting to your instance.
    • Security Group:
      • Allow HTTP (port 80), HTTPS (port 443), and SSH (port 22).
    • Launch the instance.

EC2 Lunch Wizard2


Step 2: Access Your EC2 Instance

  1. SSH into the EC2 Instance
    • Open your terminal or SSH client and connect using the command below. Replace your-key.pem with the path to your key file and your-ec2-public-ip with the public IP of your EC2 instance.
   ssh -i "your-key.pem" ubuntu@your-ec2-public-ip
Enter fullscreen mode Exit fullscreen mode

SSH into EC2

  1. Update the System
    • It is good practice to update your package list and upgrade existing packages to ensure your system is secure and up-to-date.
   sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Step 3: Install Necessary Software

  1. Install Apache, PHP, and MySQL Client
    • Apache will serve your website, PHP will process the server-side scripts, and MySQL client will help in managing databases.
   sudo apt install apache2 php php-mysql mariadb-client curl unzip -y
Enter fullscreen mode Exit fullscreen mode
  1. Remove the Default Apache Landing Page
    • This step ensures that Apache serves the WordPress site instead of its default landing page.
   sudo rm /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode
  1. Restart Apache
    • Restarting Apache applies the changes and ensures it runs correctly.
   sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

Step 4: Launch an RDS Instance

  1. Go to the AWS Console > RDS > Create Database
    • Navigate to RDS in the AWS Console.

RDS Window

  1. Configure the Database
    • Engine: Select MySQL.
    • DB Instance Class: Choose db.t2.micro (free tier eligible).
    • Storage: Allocate 20 GB.
    • Username: Set as admin.
    • Password: Set as yourpassword.
    • Public Access: Enable to allow EC2 to connect.
    • Security Group: Allow MySQL/Aurora (port 3306).

RDS configuration

  1. Launch the Database
    • Click the Create Database button to launch your RDS instance.

Step 5: Create and Configure the Database

  1. Note the RDS Endpoint

    • Open the RDS dashboard and note down the Endpoint. You will use this to connect from your EC2 instance.
  2. SSH into Your EC2 Instance

    • Connect to your RDS database from the EC2 instance using the MySQL client.
   mysql -h your-rds-endpoint -u admin -p
Enter fullscreen mode Exit fullscreen mode
  1. Create the WordPress Database
    • In the MySQL prompt, execute the following command to create a new database for WordPress.
   CREATE DATABASE wordpress;
   EXIT;
Enter fullscreen mode Exit fullscreen mode

Step 6: Download and Configure WordPress

  1. Download WordPress
    • Use curl to download the latest version of WordPress, extract it, and move it to the web root directory.
   curl -O https://wordpress.org/latest.tar.gz
   tar -xzvf latest.tar.gz
   sudo mv wordpress /var/www/html/
Enter fullscreen mode Exit fullscreen mode
  1. Set Permissions
    • Set the correct permissions to ensure that Apache can manage the WordPress files.
   sudo chown -R www-data:www-data /var/www/html/wordpress
   sudo chmod -R 755 /var/www/html/wordpress
Enter fullscreen mode Exit fullscreen mode
  1. Edit the wp-config.php File
    • Rename the sample configuration file and edit it to include your database details.
   sudo nano /var/www/html/wordpress/wp-config-sample.php
Enter fullscreen mode Exit fullscreen mode
   define('DB_NAME', 'wordpress');
   define('DB_USER', 'admin');
   define('DB_PASSWORD', 'yourpassword');
   define('DB_HOST', 'your-rds-endpoint');
Enter fullscreen mode Exit fullscreen mode
  • Save the file as wp-config.php.
   sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
Enter fullscreen mode Exit fullscreen mode

Wordpress config

Step 7: Configure Apache

  1. Create a Virtual Host Configuration File
    • Create a new configuration file for your WordPress site.
   sudo nano /etc/apache2/sites-available/wordpress.conf
Enter fullscreen mode Exit fullscreen mode
  1. Add the Virtual Host Configuration
    • Add the following configuration to the file.
   <VirtualHost *:80>
       DocumentRoot /var/www/html/wordpress
       <Directory /var/www/html/wordpress>
           AllowOverride All
       </Directory>
   </VirtualHost>
Enter fullscreen mode Exit fullscreen mode

Virtual Host config

  1. Enable the Site and Rewrite Module
    • Enable the WordPress site and the rewrite module.
   sudo a2ensite wordpress
   sudo a2enmod rewrite
   sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

Step 8: Finalize WordPress Installation

  1. Open Your Browser
    • Navigate to http://your-ec2-public-ip to access the WordPress setup wizard.

Wordpress installation

  1. Complete the Setup Wizard
    • Follow the instructions to enter your site title, admin credentials, and other necessary information.

Step 9: Troubleshooting Tips

  1. Cannot Connect to RDS
    • Ensure

Top comments (0)