Step-by-Step: Deploying a Web App on AWS for Beginners


 




Here is a reconstructed step-by-step guide based on the general best practices for a beginner EC2 deployment.


Step 1: Set Up Your EC2 Instance (The Virtual Server)

This step involves provisioning a virtual machine, known as an instance, to host your web application.

  1. Log in to the AWS Management Console: Access your AWS account.

  2. Launch a New EC2 Instance: Navigate to the EC2 service under the Compute section and click the "Launch Instance" button.

  3. Choose an AMI (Amazon Machine Image): Select the operating system for your server. For beginners, Amazon Linux 2 or Ubuntu are popular and great choices.

  4. Select an Instance Type: Choose the t2.micro instance type, as it's typically included in the AWS Free Tier.

  5. Configure Instance Details & Storage: You can accept most defaults. Ensure Auto-assign Public IP is set to "Enable" so the server is accessible from the internet. The default 8 GB of storage is generally sufficient.

  6. Configure Security Group (The Firewall): Create a new security group and add rules to allow incoming traffic for the following ports:

    • SSH (Port 22): To securely connect to and manage your server.

    • HTTP (Port 80): To serve non-secure web traffic.

    • HTTPS (Port 443): To serve secure web traffic.

  7. Launch Your Instance: Click "Review and Launch." When prompted, create a new key pair (a .pem file). Download and save this file securely, as it is the only way to log in to your server via SSH.


Step 2: Connect to Your EC2 Instance

Once your instance is running, you need to connect to it to install your application code and necessary software.

  1. Retrieve Connection Information: In the EC2 console, select your running instance and find its Public IPv4 address.

  2. Connect via SSH: Use your terminal (Linux/macOS) or an SSH client (Windows) with the key pair you downloaded.

    • Change key permissions (required for Linux/macOS): chmod 400 /path/to/your/keypair.pem

    • Run the SSH command: ssh -i /path/to/your/keypair.pem ec2-user@<Your-Public-IP> (Note: ec2-user is common for Amazon Linux; use ubuntu for Ubuntu AMIs).


Step 3: Install Web Server and Application Dependencies

After successfully connecting, you will prepare the environment for your web application.

  1. Update the System: Run the package manager update command (e.g., sudo yum update -y or sudo apt update -y).

  2. Install a Web Server: Install a server application like Apache or Nginx to handle web requests.

    • Example for Apache (Amazon Linux): sudo yum install httpd -y

  3. Start and Enable the Web Server: Ensure the service is running and configured to start automatically upon reboot.

    • Example for Apache: sudo systemctl start httpd and sudo systemctl enable httpd

  4. Install Application Runtimes: Install the required language runtime for your application (e.g., Node.js, Python, PHP, or Java).


Step 4: Deploy Your Application Code

The final step is to transfer your application files and start the service.

  1. Transfer Files: Use a secure file transfer protocol like SCP or SFTP to copy your local application files into the web root directory on your EC2 instance (e.g., /var/www/html/ for Apache).

  2. Configure and Run: Set up any required environment variables or database connections. If your application needs a process manager (like PM2 for Node.js), configure it to keep your app running continuously.

  3. Test: Open a web browser and navigate to your EC2 instance's Public IPv4 address. You should see your web application running.

No comments:

Post a Comment