How To Host a WordPress Website Using AWS?

Learn how to host a WordPress website on AWS. Follow this step-by-step guide to set up your domain, configure EC2, install WordPress, and secure your site with SSL.

wordpress on aws

This tutorial will walk you through hosting a WordPress website on AWS, starting from creating an AWS account to setting up a secure WordPress installation.

Step 1: Create an AWS Free Tier Account

AWS (Amazon Web Services) provides a free tier account for testing and learning purposes.To create an account:

Step 2: Register a Domain and Host DNS Zones in Amazon Route 53

Amazon Route 53 is AWS's DNS platform that allows you to register domains and manage DNS entries.

Steps to Register a Domain

  1. Log in to the AWS Console.

  2. Navigate to Networking & Content Delivery > Route 53.

  3. Choose Register Domain and follow the instructions.

    Example domain: mypagename.com (replace your link).

  4. Once registered, go to Route 53 > Hosted Zones to view your domain's name servers.

Add DNS entries in the hosted zone to manage your domain.

Step 3: Create an EC2 Instance

AWS EC2 (Elastic Compute Cloud) is used to host your WordPress site.

  1. In the AWS Console, go to Services > EC2 > Launch Instance.

  2. Select the Amazon Linux AMI. Choose the t2.micro instance type (free tier eligible).

  3. Configure the instance and:

    Download the PEM key during setup and save it securely.

    Create a new security group with ports 80, 22, and 443 open.

  4. Launch the instance.

Step 4: Install and Configure Nginx

  1. Access the Instance

  2. Navigate to your PEM key location and set permissions:

    bash
    
    chmod 400 key.pem
                                    

    SSH into the instance using the public IP:

    bash
    
    ssh -i key.pem ec2-user@ <your-ec2-public-ip>
                                    
  3. Install Nginx

  4. Update the YUM repository and install Nginx:

    bash
    
    sudo yum update -y
    sudo yum install nginx -y
    sudo service nginx start
    sudo chkconfig nginx on
    <your-ec2-public-ip>
                                    
  5. Configure Nginx

  6. Create a directory for virtual host configurations:

    bash
    
    sudo mkdir /etc/nginx/sites-enabled
                                    

    Create a configuration file for your domain:

    bash
    
    sudo vi /etc/nginx/sites-enabled/mypagename.com.conf
                                    

    Add the following configuration:

    nginx

    bash
    
    server {
    listen 80;
    listen [::]:80;
    root /home/myblog/;
    index index.html index.htm index.php;
    server_name mypagename.com www.mypagename.com;
    
    location / {
        try_files $uri $uri/ =404;
    }
    }
                                    

    Test the Nginx configuration and restart the service:

    bash
    
    sudo nginx -t
    sudo service nginx restart
                                    

Step 5: Install WordPress

  1. Download WordPress

  2. Navigate to the document root for your website:

    bash
    
    cd /home/myblog/
                                    

    Download and extract WordPress:

    bash
    
    wget https://wordpress.org/latest.tar.gz
    tar -xvzf latest.tar.gz
    mv wordpress/* .
    rm -rf latest.tar.gz wordpress/
                                    

Step 6: Install Let’s Encrypt SSL Certificate

  1. Install Dependencies

  2. bash
    
    sudo yum install python27-devel git
    git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
                                    
  3. Run Certbot for SSL Installation

  4. bash
    
    sudo /opt/letsencrypt/letsencrypt-auto --debug
                                    

    a. Provide the domain name and email address during the process.

    b. Certbot automatically adds SSL configurations to your Nginx file.

  5. Example HTTPS Block

    nginx

  6. bash
    
    server {
    listen 443 ssl;
    root /home/myblog/;
    index index.html index.htm index.php;
    server_name mypagename.com www.mypagename.com;
    
    location / {
        try_files $uri $uri/ =404;
    }
    }
                                    

Step 7: Redirect HTTP to HTTPS

To ensure all traffic uses HTTPS, add this directive to the port 80 server block:

nginx

bash

rewrite ^ https://$host$request_uri? permanent;
                                

Step 8: Point Your Domain to the EC2 Instance

  1. Navigate to Route 53 > Hosted Zones in the AWS Console.

  2. Create an A Record pointing to your EC2 instance’s public IP for both

Conclusion

You have successfully set up a WordPress website on AWS! By following these steps, you now have a functional website hosted on a secure and scalable AWS infrastructure. Explore additional features like RDS for databases or Elastic Load Balancing for improved performance and reliability.

Discover iDatam Dedicated Server Locations

iDatam servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.

Up