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:
- How to Launch a GCP Compute Engine Linux Instance
- Configuring Firewall Rules to Secure and Access a VM
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.