How to Create and Deploy a WordPress Website on AWS Platform

Learn how to create and deploy a WordPress website on AWS Platform EC2 using Apache, MySQL, and PHP. This step-by-step guide walks you through setting up a virtual server, installing necessary software, configuring your domain, and securing your site with HTTPS. Perfect for beginners looking to host a custom WordPress website on the cloud.

You can actually deploy a WordPress website in just one click using AWS LightSail. However, in this guide, we’re going to take the traditional approach. We’ll manually set up all the necessary elements, allowing you to learn and gain hands-on experience in the process. The steps will involve renting a virtual computer (EC2 instance) on AWS, installing the necessary software (Apache, MySQL, WordPress), and configuring everything to make your website live.


1. Setting Up AWS EC2 Instance:

First, we’ll create a virtual computer on AWS EC2. This will act as the server where WordPress will be installed. From the AWS Management Console, go to the EC2 dashboard, click on “Launch Instance,” and name your instance (e.g., “My WordPress Server”). Choose Ubuntu as the operating system and the t2.micro instance type for a lightweight server. Then, create a new key pair for secure access, configure network settings to allow HTTP and HTTPS traffic, and launch the instance.


2. Assigning an Elastic IP Address:

Next, to ensure that your server’s IP address remains static (even if you reboot the instance), assign an Elastic IP. Go to the Elastic IPs section, allocate a new IP address, and associate it with the newly created EC2 instance. This IP will be used to access the website.


3. Connecting to the EC2 Instance:

Once the instance is up and running, you can connect to it via SSH. Use a terminal (or MobaXterm on Windows) to log in using the SSH key you downloaded earlier. You will need the instance’s public IP address and the Ubuntu username to establish the connection.


4. Installing Apache Web Server:

After connecting to the EC2 instance, install Apache, which will act as the web server. Use the command sudo apt install apache2. Verify that Apache is running by accessing your server’s IP in the browser — if you see the default Apache page, the installation was successful.


5. Installing PHP and MySQL:

Since WordPress is built with PHP, you’ll need to install the PHP runtime and the MySQL database server. Use the following commands:

  • sudo apt install php libapache2-mod-php
  • sudo apt install mysql-server

6. Configuring MySQL:

Once MySQL is installed, log in to the MySQL prompt using sudo mysql. Change the authentication plugin for the root user to mysql_native_password and create a new database and user for WordPress.

Commands:

sqlCopy codeALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE wp;
GRANT ALL PRIVILEGES ON wp.* TO 'wp_user'@'localhost';

7. Installing WordPress:

Download the latest version of WordPress from wordpress.org. Extract the files and move them to the Apache web root directory:

bashCopy codesudo mv wordpress /var/www/html/

Afterward, navigate to http://<your-public-ip>/wordpress to start the WordPress installation.


8. Configuring WordPress:

On the WordPress installation page, enter your database details:

  • Database Name: wp
  • Username: wp_user
  • Password: password
  • Database Host: localhost

If the system throws an error about the wp-config.php file, manually create this file in the WordPress directory, paste the configuration code, and save it. Then, complete the installation process by choosing a site name, setting an admin username and password, and installing WordPress.


9. Setting Up the Domain Name:

To make your website accessible via a custom domain, purchase a domain and configure it in your DNS settings. Point the domain to the EC2 instance’s static IP address by adding an A record in your domain’s DNS settings. Then, modify Apache’s configuration to use your domain name. Update the 000-default.conf file to reflect your domain name in the ServerName and ServerAlias fields.


10. Enabling SSL with HTTPS:

For security, configure HTTPS on your WordPress website by installing an SSL certificate. Use Let’s Encrypt and Certbot to generate and install the certificate:

bashCopy codesudo apt install certbot python3-certbot-apache
sudo certbot --apache

Follow the prompts to complete the SSL installation for both the root domain and the www subdomain.


Conclusion:

After the DNS changes propagate (10-15 minutes), your WordPress website will be accessible securely over HTTPS using your custom domain. You’ve successfully created and deployed a WordPress site on AWS, and now you can customize and manage your website through the WordPress dashboard.

Leave a Comment