AWS EC2 and Amazon Linux: Preparing Amazon Linux for High Availability Web Server

Before you can deploy a highly available web server on AWS EC2 using Amazon Linux, you need to prepare your environment. This article covers the steps to set up Amazon Linux on an EC2 instance, including instance creation, security group configuration, and necessary package installations.

Prerequisites:

  • An AWS account
  • Basic knowledge of AWS and Linux commands

Steps:

  1. Create an EC2 Instance:
    Log in to the AWS Management Console and navigate to the EC2 Dashboard. Click on the Launch Instance button. Choose the Amazon Linux 2 AMI as your Amazon Machine Image (AMI).
    Select an instance type that suits your needs. For this tutorial, the t2.micro instance type is sufficient.
    Configure the instance details, including network settings. Ensure that you select a VPC and subnet that meet your requirements. Enable Auto-assign Public IP if you need your instance to be publicly accessible.
  2. Configure Security Group:
    Create a new security group or use an existing one. Configure the following inbound rules:

    • HTTP: Port 80, Source: 0.0.0.0/0 (Anywhere)
    • HTTPS: Port 443, Source: 0.0.0.0/0 (Anywhere)
    • SSH: Port 22, Source: your IP address (for secure access)
  3. Launch the Instance:
    Review your instance configuration and click Launch. Select an existing key pair or create a new one to access your instance via SSH. Click Launch Instances to start your instance.
  4. Connect to Your Instance:
    Once your instance is running, connect to it using SSH. Use the following command, replacing your-key-pair.pem and your-instance-public-dns with your key pair file and instance public DNS:

    ssh -i your-key-pair.pem ec2-user@your-instance-public-dns
  5. Update and Install Necessary Packages:
    After connecting to your instance, update the package list and install necessary packages:

    sudo yum update -y
    sudo yum install -y httpd mariadb-server php php-mysqlnd

    Start and enable the Apache web server and MariaDB database server:

    sudo systemctl start httpd
    sudo systemctl enable httpd
    sudo systemctl start mariadb
    sudo systemctl enable mariadb

With these steps, you have successfully prepared your Amazon Linux instance for hosting a highly available web server. In the next article, we will cover the installation and configuration of WordPress on your web server.