Guided Lab: Installing WordPress on an Ubuntu VM Instance with LEMP Stack
Description
Google Cloud Compute Engine allows you to create and run virtual machines (VMs) on Google’s infrastructure. By configuring a VM with the LEMP stack (Linux, Nginx, MySQL, PHP), you can host dynamic websites and applications directly in the cloud.
LEMP is an open-source web application stack that we may use to create web apps. LEMP’s abbreviation stands for Linux Operating System, Nginx (pronounced engine-x), web server, MySQL database, and PHP programming language.
- Linux is available as a supported and maintained image in Google Cloud. Compute Engine provides multiple Linux distributions, such as Ubuntu and Debian, that are optimized to run securely and efficiently on Google’s infrastructure.
- Nginx, which is pronounced “engine-x,” is a high-performance web server and reverse proxy. It excels at handling concurrent connections, serving static files, and load balancing. Many websites use Nginx due to its efficiency and scalability.
- MySQL is a widely used open-source relational database management system (RDBMS) that organizes data in tables with rows and columns, making it ideal for applications requiring structured data storage. WordPress, among others, relies on MySQL for data persistence.
- PHP is a server-side scripting language used for web development. It enables dynamic content generation, database connectivity, and interaction with web servers. WordPress plugins and themes often leverage PHP for customization.
WordPress is a widely used open-source content management system (CMS) that allows users to easily create and manage websites, blogs, and online stores. It offers a user-friendly interface, customizable themes, and a wide array of plugins for additional functionality.
This lab will guide you through installing WordPress on an Ubuntu VM instance, configuring Nginx to serve PHP content, setting up a database, and verifying that WordPress is accessible externally.
Prerequisites
To ensure the successful completion of this lab, we highly recommend taking these guided labs to gain the necessary understanding:
- Guided Lab: How to Launch a GCP Compute Engine Linux Instance
- Guided Lab: Setting up a Web Server on a VM Instance
- Guided Lab: Setting Up and Managing a Database on a VM Instance
Objectives
In this lab, you will:
- Create an Ubuntu VM instance in Google Cloud.
- Install and configure Nginx, MySQL, and PHP.
- Configure Nginx for WordPress.
- Create a WordPress database and user.
- Download and configure WordPress.
- Verify WordPress installation via a browser.
Lab Steps
Create a Compute Engine VM Instance
1. Create a VM instance using the following machine configurations:
- Name: Enter your desired instance name.
- Machine type: Choose e2-small (Preset)

2. Under OS and storage, click the Change button to modify the Boot disk:
- Operating System: Ubuntu
- Version: 24.04 LTS Minimal (x86/64, amd64 noble minimal image built on 2025‑12‑17)

3. Under Network → Firewall, check:
- Allow HTTP traffic

3. Leave other configurations at their default values.
4. Click Create and wait until the VM is running.
Install the NGINX (Web Server)
1. SSH into the VM from the console.
2. Run the following commands:
# Update system
sudo apt update -y

# Install Nginx
sudo apt install nginx

Press y if prompted to continue.
3. Verify installation: open your VM’s Public IPv4 address in a browser. You should see the default Nginx welcome page.

Install the MySQL
1. Go back to the SHH and install MySQL.
sudo apt install mysql-server -y
2. To verify successful installation, enter mysql –version command.

Install the PHP and Required extensions
1. Install PHP and extensions:
sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip -y

2. To verify successful installation, enter the php --version command.

Configure the Nginx for WordPress
Note: For the purposes of this lab, we’ll use the domain name “demo” in all our configurations. Feel free to replace “demo” with your desired name.
Before editing configuration files, install Vim (or use Nano if you prefer):
sudo apt install vim -y

1. Create a Directory for Your WordPress Site:
sudo mkdir /var/www/demo
2. Set Permissions for the Directory:
sudo chown -R $USER:$USER /var/www/demo – It sets the owner and group to the current user (ubuntu).
3. Create an Nginx Configuration File for Your Site:
sudo vi /etc/nginx/sites-available/demo – This will generate a new empty file. Paste the following configuration (replace your_IPv4 with your VM’s Public IPv4 address):
Type i to edit the file.
server {
listen 80;
server_name your_IPv4;
root /var/www/demo;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

4. Press ESC, then:wq! to save the changes.
5. Link to the configuration file from Nginx’s sites-enabled directory to activate your setup:
sudo ln -s /etc/nginx/sites-available/demo /etc/nginx/sites-enabled/
6. Then, under the /sites-enabled/ directory, unlink the default configuration file:
sudo unlink /etc/nginx/sites-enabled/default
7. You can test your configuration for syntax errors by typing:
sudo nginx -t

If any issues are reported, return to your configuration file and double-check its contents before proceeding.
8. When you’re finished, reload Nginx to make the changes take effect:
sudo systemctl reload nginx
Create a MySQL Database and User for WordPress
1. Open the MySQL.sudo mysql
2. Create Database:CREATE DATABASE demo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
3. Create User and Grant Permissions:CREATE USER 'demo_user'@'localhost' IDENTIFIED BY 'demo123';GRANT ALL ON demo.* TO 'demo_user'@'localhost';
4. Exit when done.exit

Download and Set Up WordPress
1. Navigate to the /tmp directory.cd /tmp
2. Download the latest WordPress package, and extract it.
curl -LO https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz

3. Configure WordPress:
# Copy the sample configuration file to wp-config.php for customization.sudo cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
# Copy WordPress files to the /var/www/demo directory.sudo cp -a /tmp/wordpress/. /var/www/demo
# Set the ownership to www-datasudo chown -R www-data:www-data /var/www/demo
4. Edit wp-config.php to add database details:sudo vi /var/www/demo/wp-config.php
Press i to edit.

Press ESC, then enter :wq! to save the changes.
5. Generate security keys:curl -s https://api.wordpress.org/secret-key/1.1/salt/
6. Copy the output and paste it into wp-config.php, replacing the placeholders.sudo vi /var/www/demo/wp-config.php
Press i to edit the file.

Press ESC, then enter :wq! to save the changes.
7. Restart the PHP-FPMsudo systemctl restart php8.3-fpm
Complete WordPress Installation
1. In your browser, visit:
http://<VM_EXTERNAL_IP>/wordpress
2. Follow the WordPress setup wizard.

That’s it! You have successfully created an Ubuntu VM instance, installed and configured the LEMP stack, set up Nginx for WordPress, created a database and user, and deployed WordPress with the necessary configuration. Your WordPress site is now live and accessible through your VM’s public IP address. This lab demonstrates how to host a dynamic CMS on Google Cloud and provides a strong foundation for exploring advanced topics such as enabling HTTPS with Let’s Encrypt, scaling with load balancers and instance groups, and strengthening security with firewall rules and IAM policies.