Simplifying Web Server setup with Compute Engine Startup Script V2 | Scribe

    Simplifying Web Server setup with Compute Engine Startup Script V2

    • Hafeez Baig |
    • 13 steps |
    • 59 seconds
    1
    Sign in into the **Google Cloud Platform**
    2
    Type "**Compute Engine**" in the search bar and click on the **Compute Engine** option
    information ordinal icon
    **What is a Compute Engine?** Google Compute Engine (GCE) is an Infrastructure-as-a-Service (IaaS) offering from Google Cloud Platform (GCP) that allows users to run virtual machines (VMs) on Google's infrastructure. It provides scalable and flexible computing resources, high-performance persistent storage, advanced networking capabilities, and integration with other GCP services, making it suitable for a variety of workloads including web hosting, data processing, and high-performance computing.
    3
    **VM instances** wizard will open, click on the **CREATE INSTANCE** button on the top left side
    4
    **Create an instance** wizard will open, give the Name as - **"my-vm-with-startup-script"**
    5
    Scroll to the **Firewall** section and select the option **Allow HHTP traffic**
    information ordinal icon
    **What is the Allow HTTP traffic option?**\ \ The "Allow HTTP traffic" option in Google Cloud Platform (GCP) is a firewall setting for virtual machine instances. When enabled, it creates a firewall rule that permits incoming HTTP traffic (port 80) to the VM, allowing web servers hosted on the VM to be accessible via the HTTP protocol.
    6
    Scroll to the **Advanced options** section and click on the dropdown
    7
    Scroll and click on the **Management** dropdown section
    8
    Scroll to the **Automation** section and type the script\ \ [[#!/bin/bash ]]\ [[apt update apt -y install apache2 ]]\ [[echo "Hello World from $(hostname) $(hostname -i)" > /var/www/html/index.html]]
    information ordinal icon
    **What is start script - automation?**\ \ A start script in automation is a predefined set of commands or a script that runs automatically when a system or application starts. It automates initial setup tasks, configuration, and other necessary processes to ensure the environment is ready for use.
    information ordinal icon
    The Automation script performs the following tasks: 1. `#!/bin/bash`: Specifies that the script should be run in the Bash shell. 2. `apt update`: Updates the package list on the system to ensure you have the latest information on available packages. 3. `apt -y install apache2`: Installs the Apache2 web server without prompting for confirmation, making the process non-interactive. 4. `echo "Hello World from $(hostname) $(hostname -i)" > /var/www/html/index.html`: Creates a "Hello World" web page that includes the hostname and IP address of the machine, and writes it to the default web directory. **In summary**, this script ensures your package list is up-to-date, installs the Apache2 web server, and customizes the default web page to display a "Hello World" message along with the machine's hostname and IP address.
    9
    Scroll the page and click on the **CREATE** button
    10
    On the top right corner click on the **Notifications** icon, here you can see that the VM instance has been successfully created
    information ordinal icon
    Congratulations you have successfully created a VM instance with the Web Server installed in it with advance automation script
    11
    On **VM instances** wizard, scroll to the **External IP** section and click on copy widget
    12
    Open the new tab in browser and paste the copied **External IP** address
    13
    **Hello World from my-vm-with-startup-script 10.128.0.3** will be displayed
    information ordinal icon
    Congratulations on completing this lab and Simplifying the Web Server setup with Compute Engine Startup Script V2 in the Google Cloud Platform