Ends in
00
days
00
hrs
00
mins
00
secs
SHOP NOW

🚀 30% OFF All Solutions Architect Reviewers

Back to Course

GCP PlayCloud Labs

0% Complete
0/0 Steps
  1. GCP PlayCloud Labs
  2. Guided Lab: Creating a Cloud Storage Bucket
  3. Guided Lab: How to Launch a GCP Compute Engine Linux Instance
  4. Guided Lab: Creating a Cloud SQL Instance
  5. Guided Lab: Creating a Cloud NAT Gateway
  6. Guided Lab: Running SQL Commands in Cloud SQL Studio
  7. Guided Lab: Hosting a Static Website in Google Cloud Storage Bucket
  8. Guided Lab: Creating and Restoring Cloud SQL Backups
  9. Guided Lab: Vertically Scaling a VM Instance
  10. Guided Lab: Creating a Custom Image from a VM Instance with Web Server in Google Cloud
  11. Guided Lab: Setting up a Web Server on a VM Instance
  12. Guided Lab: Creating a Spot VM Instance
  13. Guided Lab: Exploring Instance Metadata in Google Cloud
  14. Guided Lab: Setting Up and Managing a Database on a VM Instance
  15. Guided Lab: Integrating Cloud SQL Database instance with a VM instance
  16. Guided Lab: Connecting Cloud SQL Database with MySQL Workbench (Local)
  17. Guided Lab: Creating a VM Using Instance Templates
  18. Guided Lab: Installing WordPress on an Ubuntu VM Instance with LEMP Stack
  19. Guided Lab: Reserving or Promoting a Static IP Address for a VM Instance
  20. Guided Lab: Creating a Google Kubernetes Engine (GKE) Cluster
  21. Guided Lab: Protecting Data on Cloud Storage Bucket Against Accidental Delete and Overwrite Using Object Versioning
  22. Guided Lab: Connecting to a Kubernetes Engine Cluster
  23. Guided Lab: Creating and Managing Instance Groups in Compute Engine
  24. Guided Lab: Configuring Shielded VM Options
  25. Guided Lab: SSH Access to GCP VM Instance from Local Machine using SSH Key Pair
  26. Guided Lab: Deploying a Simple Web Application on GKE
  27. Guided Lab: Configuring Firewall Rules to Secure and Access a VM
  28. Guided Lab: Establishing VPC Peering for Secure Cross‑Network Communication
  29. Guided Lab: Creating a Custom Virtual Private Cloud (VPC)
  30. Guided Lab: Using Startup Scripts in GCP VM Instances
  31. Guided Lab: Deploying a LAMP Stack on a Compute Engine VM
  32. Guided Lab: Managing Cloud Storage Buckets via SSH Commands
  33. Guided Lab: Guarding Your VM with Deletion Protection
  34. Guided Lab: Using Cloud Storage Lifecycle Rules to Automate Object Management
  35. Guided Lab: Guarding Your Cloud SQL Instances with Deletion Protection
  36. Guided Lab: Exploring Google Cloud Storage Classes
  37. Guided Lab: Setting Up a Linux Bastion Host on GCP
  38. Guided Lab: Uploading, Organizing, and Managing Objects in Cloud Storage
  39. Guided Lab: Creating an Application Load Balancer
  40. Guided Lab: Creating a Network Load Balancer
  41. Guided Lab: Creating VM Snapshots and Restoring a VM from a Snapshot
Lesson 31 of 41
In Progress

Guided Lab: Deploying a LAMP Stack on a Compute Engine VM

Description

A LAMP stack (Linux, Apache, MySQL, and PHP) is a common setup used to host dynamic websites and web applications. Running a LAMP stack on a virtual machine allows you to fully control the server environment and understand how web applications are deployed at the infrastructure level.

In this guided lab, you’ll launch a Compute Engine VM and install the components of a LAMP stack. You’ll configure the web server and database, deploy a simple PHP application, and verify the setup by accessing it through a browser. This lab provides hands-on experience with deploying and validating a traditional web application stack on Google Cloud.

Prerequisites

This lab assumes you are familiar with Compute Engine VM instances and accessing it through SSH

If you find any gaps in your knowledge, consider taking the following labs:

 

Objectives

In this lab, you will:

  • Launch a Linux VM in Google Compute Engine
  • Install and configure a LAMP stack (Apache, MySQL, PHP)
  • Configure firewall rules to allow HTTP traffic
  • Verify web server functionality in a browser

Lab Steps

Launching a Linux VM Instance

1. In the Google Cloud console, use the unified search bar to navigate to Compute Engine.

2. Click VM instances, then click Create Instance.

3. Configure the VM instance with the following:

  • Name: <your desired VM name>
  • Machine type: e2-micro
  • Go to the OS and storage tab, then click Change, then change the Operating system and version to Ubuntu

4. Leave the remaining settings at their default values and click Create.

Configure firewall rules

1. Navigate to VPC network → Firewall in the Cloud console.

2. Click Create Firewall Rule.

3. Create a firewall rule to allow HTTP traffic with the following configurations:

  • Name: allow-http-traffic (or any name you desire)
  • Network: default (where your VM’s VPC currently is)
  • Targets: All instances in the network (or specify tags)
  • Source IP ranges: 0.0.0.0/0 (allow from anywhere)
  • Protocols and ports: Select Specified protocols and ports → tcp:80
Connecting to your VM and Installing LAMP stack

1. Go back to Compute Engine → VM Instances in the Google Cloud console.

2. Find your created VM and click SSH to connect. Take notice of its External IP

3. Update the package manager:

sudo apt update

4. Install Apache:

    sudo apt install apache2 -y
    sudo systemctl start apache2
    sudo systemctl enable apache2

    5. Install MySQL:

      sudo apt install mysql-server -y
      sudo mysql_secure_installation

      Answer the following MySQL security installation setup prompts with the following:

      • Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: N
      • Remove anonymous users? (Press y|Y for Yes, any other key for No) : N
      • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
      • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
      • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

      6. Install PHP and link it with Apache:

      sudo apt install php libapache2-mod-php php-mysql -y
      sudo systemctl restart apache2

      ⚠️ If this error shows up on your end: “sudo-rs: I'm sorry <username>. I'm afraid I can't do that“, just close the SSH browser then start another SSH session.

      Testing VM Connectivity

      1. In a browser, enter the VM’s external IP (e.g., http://34.70.130.41). You should see the Apache default web page, confirming HTTP access.

      2. To verify if PHP is working, go to the SSH terminal of your VM, then run the following:

      echo "<?php echo 'Mabuhay! Your LAMP stack is working.'; ?>" | sudo tee /var/www/html/info.php

      3. Open a browser, then enter the following code below. You should see a message that confirms that the LAMP stack is fully functional:

      http://<EXTERNAL-IP>/info.php

      Well done! You’ve successfully deployed a LAMP stack on a Compute Engine VM and verified that Apache, MySQL, and PHP are running correctly. This guided lab helps you understand how to set up a web server in Google Cloud, configure firewall rules, and test connectivity. You can use these same concepts to deploy dynamic websites and web applications, and in future guided labs, you’ll explore advanced server configurations, database management, and web application hosting.

      Skip to content