Home / Linux System Administration / Setting up AWS Virtual Hosting Amazon Linux

Setting up AWS Virtual Hosting Amazon Linux

1) Create Linux Instance

Set Up an AWS EC2 Instance

  1. Open your browser and visit https://aws.amazon.com
  2. Click “Sign In to the Console”.
  3. Log in with your AWS credentials.

Launch an EC2 Instance

  1. In the AWS Console, search for “EC2” in the search bar and click on it.
  2. Click the “Launch Instance” button.
  3. Give your instance a name (e.g., MyWebServer).

Choose an AMI (Amazon Machine Image)

  1. Select Amazon Linux 2023 (or Amazon Linux 2).
  2. This is a free-tier eligible image ideal for beginners.

Choose an Instance Type

  1. Select t3.micro (free-tier eligible).

Configure Key Pair (SSH Access)

  1. Under Key pair (login), choose “Create new key pair”.
  2. Give it a name (e.g., my-key).
  3. Select .pem format if using Linux/macOS, or .ppk for Windows PuTTY.
  4. Click Create key pair and it will download automatically — keep it safe!

Allow,

  1. SSH traffic from
  2. HTTPS traffic from the internet
  3. HTTP traffic from the internt

Launch the Instance

  1. Click “Launch Instance”.
  2. Wait a few seconds, then click “View all instances”.

2) Connect to Your Instance        

On Windows (with PuTTY):

  1. Open PuTTYgen and convert your .pem to .ppk (if needed).
  2. Open PuTTY:
  3. Host Name: Instance – Public IPv4 address
  4. Port 22
  5. In Connection > SSH > Auth – Credentials, browse and select your .ppk file.
  6. Go to Session – Click Open
  7. Accept
  8. login as ec2-user

     3) Package installation

Apache

  1. Install Apache (httpd): sudo yum install httpd -y
  2. Start Apache: sudo systemctl start httpd
  3. Enable Apache: sudo systemctl enable httpd

      MariaDB

  1. Install MariaDB: sudo yum install mariadb105-server -y
  2. Start MariaDB:  sudo systemctl start mariadb
  3. Enable MariaDB: sudo systemctl enable mariadb

      PHP

  1. Install PHP: sudo yum install php php-mysqlnd -y

3) Map Your Domain to Your AWS EC2 Instance

  1. Before setting up virtual hosting, you need to map your domain to your EC2 instance using your domain registrar (e.g., Namecheap, GoDaddy, Google Domains)
  2. After saving the records, DNS propagation may take a few minutes to several hours.

4) Virtual host Configuration

  1. Create a directory for your website
    1. sudo mkdir /var/www/html/yourdomain.com
  2. Set the correct permissions
    1. sudo chown -R ec2-user:ec2-user /var/www/yourdomain.com
  3. Add a test html page (Edit and create sample HTML file using vi)
    1. vi index.html
  4. Create a virtual host configuration file
    1. sudo cd /etc/httpd/conf.d
    1. vi yourdomain.com.conf
  5. Paste the following configuration

<VirtualHost *:80>

    ServerName yourdomain.com

    ServerAlias www.yourdomain.com

    DocumentRoot /var/www/yourdomain.com/public_html

    ErrorLog /var/log/httpd/yourdomain.com-error.log

    CustomLog /var/log/httpd/yourdomain.com-access.log combined

</VirtualHost>

  • Restart Apache to apply changes
    • sudo systemctl restart httpd

Leave a Reply

Your email address will not be published. Required fields are marked *