1) Create Linux Instance
Set Up an AWS EC2 Instance
- Open your browser and visit https://aws.amazon.com
- Click “Sign In to the Console”.
- Log in with your AWS credentials.
Launch an EC2 Instance
- In the AWS Console, search for “EC2” in the search bar and click on it.
- Click the “Launch Instance” button.
- Give your instance a name (e.g., MyWebServer).
Choose an AMI (Amazon Machine Image)
- Select Amazon Linux 2023 (or Amazon Linux 2).
- This is a free-tier eligible image ideal for beginners.
Choose an Instance Type
- Select t3.micro (free-tier eligible).
Configure Key Pair (SSH Access)
- Under Key pair (login), choose “Create new key pair”.
- Give it a name (e.g., my-key).
- Select .pem format if using Linux/macOS, or .ppk for Windows PuTTY.
- Click Create key pair and it will download automatically — keep it safe!
Allow,
- SSH traffic from
- HTTPS traffic from the internet
- HTTP traffic from the internt
Launch the Instance
- Click “Launch Instance”.
- Wait a few seconds, then click “View all instances”.
2) Connect to Your Instance
On Windows (with PuTTY):
- Open PuTTYgen and convert your .pem to .ppk (if needed).
- Open PuTTY:
- Host Name: Instance – Public IPv4 address
- Port 22
- In Connection > SSH > Auth – Credentials, browse and select your .ppk file.
- Go to Session – Click Open
- Accept
- login as ec2-user
3) Package installation
Apache
- Install Apache (httpd): sudo yum install httpd -y
- Start Apache: sudo systemctl start httpd
- Enable Apache: sudo systemctl enable httpd
MariaDB
- Install MariaDB: sudo yum install mariadb105-server -y
- Start MariaDB: sudo systemctl start mariadb
- Enable MariaDB: sudo systemctl enable mariadb
PHP
- Install PHP: sudo yum install php php-mysqlnd -y
3) Map Your Domain to Your AWS EC2 Instance
- 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)
- After saving the records, DNS propagation may take a few minutes to several hours.
4) Virtual host Configuration
- Create a directory for your website
- sudo mkdir /var/www/html/yourdomain.com
- Set the correct permissions
- sudo chown -R ec2-user:ec2-user /var/www/yourdomain.com
- Add a test html page (Edit and create sample HTML file using vi)
- vi index.html
- Create a virtual host configuration file
- sudo cd /etc/httpd/conf.d
- vi yourdomain.com.conf
- 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