Documentation: Install WordPress on EC2 with RDS
Victor Okonkwo
Posted on November 27, 2024
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
- Log in to the AWS Management Console
- Navigate to the AWS Management Console at aws.amazon.com/console.
- Navigate to EC2
- In the AWS Console, search for EC2 in the search bar and select it.
-
Launch a New Instance
- Click on Launch Instances.
-
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.
-
Name:
Step 2: Access Your EC2 Instance
-
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 andyour-ec2-public-ip
with the public IP of your EC2 instance.
- Open your terminal or SSH client and connect using the command below. Replace
ssh -i "your-key.pem" ubuntu@your-ec2-public-ip
-
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
Step 3: Install Necessary Software
-
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
-
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
-
Restart Apache
- Restarting Apache applies the changes and ensures it runs correctly.
sudo systemctl restart apache2
Step 4: Launch an RDS Instance
-
Go to the AWS Console > RDS > Create Database
- Navigate to RDS in the AWS Console.
-
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).
-
Launch the Database
- Click the Create Database button to launch your RDS instance.
Step 5: Create and Configure the Database
-
Note the RDS Endpoint
- Open the RDS dashboard and note down the Endpoint. You will use this to connect from your EC2 instance.
-
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
-
Create the WordPress Database
- In the MySQL prompt, execute the following command to create a new database for WordPress.
CREATE DATABASE wordpress;
EXIT;
Step 6: Download and Configure WordPress
-
Download WordPress
- Use
curl
to download the latest version of WordPress, extract it, and move it to the web root directory.
- Use
curl -O https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo mv wordpress /var/www/html/
-
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
-
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
define('DB_NAME', 'wordpress');
define('DB_USER', 'admin');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'your-rds-endpoint');
- Save the file as
wp-config.php
.
sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
Step 7: Configure Apache
-
Create a Virtual Host Configuration File
- Create a new configuration file for your WordPress site.
sudo nano /etc/apache2/sites-available/wordpress.conf
-
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>
-
Enable the Site and Rewrite Module
- Enable the WordPress site and the rewrite module.
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo systemctl restart apache2
Step 8: Finalize WordPress Installation
-
Open Your Browser
- Navigate to
http://your-ec2-public-ip
to access the WordPress setup wizard.
- Navigate to
-
Complete the Setup Wizard
- Follow the instructions to enter your site title, admin credentials, and other necessary information.
Step 9: Troubleshooting Tips
-
Cannot Connect to RDS
- Ensure
💖 💪 🙅 🚩
Victor Okonkwo
Posted on November 27, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined I absolutely love when CSS gets new features (Even though it usually takes me years to remember to use them 😄)
November 27, 2024