Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 3, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 3, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 3, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 3, 2025

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 2025

      These solid-state fans will revolutionize cooling in our PCs and laptops

      June 3, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025
      Recent

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025

      A Comprehensive Guide to Azure Firewall

      June 3, 2025

      Test Job Failures Precisely with Laravel’s assertFailedWith Method

      June 3, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025
      Recent

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»AWS EC2: How to Quickly Host Your Website with User Data Scripts

    AWS EC2: How to Quickly Host Your Website with User Data Scripts

    November 26, 2024

    If you want to practice and improve your web hosting skills, this tutorial is for you. With AWS EC2 and a little magic called user data scripts, you’ll be running a stunning website with a CSS template in no time. And the best part? You don’t need to manually install everything – the user data script does all the heavy lifting for you.

    Before getting started with this guide, make sure you’ve read through my previous tutorial on AWS EC2. It covers the essentials of creating and configuring an EC2 instance. You’ll learn how to navigate the AWS Management Console, select the right instance type, configure security groups, and more.

    This foundational knowledge will make sure you’re fully prepared to launch your website effortlessly with the help of user data scripts.

    So, grab a coffee, and let’s dive into this fun and simple guide. By the end, you’ll be able to launch your own website without breaking a sweat.

    Table of Contents

    • What We’ll Cover

    • Step 1: Launch Your EC2 Instance

    • Step 2: Wait… The Script Did Everything Already?

    • Step 3: Access Your Website

    • Wrapping Up

    • Want more?

    What We’ll Cover:

    Today, we’re going to:

    • Launch an EC2 instance (Don’t worry, it’s easier than it sounds).

    • Use a user data script to automate setting up a web server.

    • Download a CSS template and host it on your instance.

    You might be wondering: why a user data script? Imagine it as a to-do list for your EC2 instance. When the instance boots up, it runs through this list and sets everything up automatically. It’s like having a personal assistant that handles all the tedious setup tasks. Sounds good, right?

    Step 1: Launch Your EC2 Instance

    First things first, head over to your AWS Management Console. This is where all the magic happens.

    Log in to AWS and head to the AWS Console. If you don’t already have an account, don’t worry, you can just sign up – it’s free for basic usage.

    Now here are the steps you’ll follow to launch the instance:

    • In the console, type EC2 in the search bar and click on the EC2 service.

    • Click the big Launch Instance button.

    • Give your instance a cool name like “Webserver”.

    • Choose Your AMI: Select the Amazon Linux 2 AMI (free-tier eligible). It’s lightweight, fast, and perfect for our use case.

    • Instance Type: Go for the t2.micro (it’s free for most use cases, and we love free things, right?).

    • User Data Script: Now, this is where things get good. Scroll down to Advanced Details, and in the User Data field, paste in the following script. This script will handle everything from installing Apache to downloading and unzipping a fancy CSS template.

    • user data script

        #!/bin/bash
      
        # Update the instance and install necessary packages
        yum update -y
        yum install -y httpd wget unzip
      
        # Start Apache and enable it to start on boot
        systemctl start httpd
        systemctl enable httpd
      
        # Navigate to the web root directory
        cd /var/www/html
      
        # Download a CSS template directly
        wget https://www.free-css.com/assets/files/free-css-templates/download/page284/built-better.zip
      
        # Unzip the template and move the files to the web root
        unzip built-better.zip -d /var/www/html/
        mv /var/www/html/html/* /var/www/html/
      
        # Clean up unnecessary files
        rm -r /var/www/html/html
        rm built-better.zip
      
        # Restart Apache to apply changes
        systemctl restart httpd
      
      • Configure Your Security Group: You want the world to be able to see your site, right? So, make sure to allow HTTP (port 80). This will let your website be accessible to anyone with the link.
    • Launch Your Instance: After double-checking everything, click Launch. AWS will ask you to choose a key pair (which you’ll need if you want to SSH into your instance later). If you don’t have one, create a new key pair.

    Boom! Your EC2 instance is launching. Grab a snack, it’ll be ready in a few minutes.

    Step 2: Wait…The Script Did Everything Already?

    Yes, that’s right! Thanks to the user data script, all the heavy lifting is done for you.

    Here’s what just happened behind the scenes:

    • Apache Web Server was installed and started.

    • A CSS template called “Built Better” was downloaded directly into the server.

    • The template was unzipped and placed in the web directory.

    All of this happened while you were sipping your coffee.

    Step 3: Access Your Website

    The exciting part is finally here! Let’s see your website in action.

    • Find Your Instance’s Public IP:

      • Head to your EC2 Dashboard, and you’ll see your running instance.

        Copy the Public IPv4 Address.

    • Open Your Browser:

      • In the address bar, type: http://your-public-ip (replace your-public-ip with the one you just copied).

      • Hit enter, and… Voilà! Your website is live, looking all professional with the “Built Better” CSS template.

    Wrapping Up

    Let’s take a moment to appreciate what you’ve accomplished:

    • Launched an EC2 instance ✔️

    • Automated the setup using a user data script ✔️

    • Hosted a slick website using a CSS template ✔️

    You’ve just dipped your toes into the world of AWS and cloud hosting. It’s not as intimidating as it sounds, right? If you enjoyed this, keep exploring AWS – the possibilities are endless. Until next time, happy coding and hosting!

    Want more?

    Follow me on Twitter or connect on LinkedIn for more awesome cloud tips and tricks. I’m always sharing helpful content and would love to hear about your cloud journey!

    You can follow me on

    • Twitter

    • LinkedIn

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleTraditional EDR won’t cut it: why you need zero trust endpoint security
    Next Article Local AI Development with Ollama Course

    Related Posts

    Security

    BitoPro Silent on $11.5M Hack: Investigator Uncovers Massive Crypto Theft

    June 3, 2025
    Security

    New Linux Vulnerabilities

    June 3, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Microsoft Issues Patches for 51 Flaws, Including Critical MSMQ Vulnerability

    Development

    Understanding the Difference Between Optimizely Configured Commerce SDK and Cloud

    Development

    NVIDIA’s next 8GB RTX GPU could arrive May 19, but here’s why buying on launch day isn’t a good idea

    News & Updates

    Unlock the power of data governance and no-code machine learning with Amazon SageMaker Canvas and Amazon DataZone

    Development

    Highlights

    Land Record System using PHP and MySQL

    December 2, 2024

    The Land Record System is a comprehensive web-based application designed to digitize and streamline the…

    JavaScript Algorithms – great for interview prep and foundational learning

    May 27, 2025

    CVE-2024-58253 – Obfstr Crate Invalid UTF-8 Conversion Vulnerability

    May 2, 2025

    Q*: A Versatile Artificial Intelligence AI Approach to Improve LLM Performance in Reasoning Tasks

    June 28, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.