Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
FREEDOM251

Freedom251 › Blog › Apache

Install a Production-Ready LAMP Stack on Google Cloud Compute Engine

By Freedom251 Team · · 12 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To install LAMP on a Google Cloud server, create a Linux Compute Engine VM, allow HTTP traffic through both Google Cloud VPC and the guest firewall, connect over SSH, and install Apache, MySQL, and PHP with Ubuntu’s package manager. Test the site over http:// first, then add a static external IP, DNS, HTTPS, least-privilege accounts, updates, backups, and monitoring before production use.

This guide uses an Ubuntu LTS VM. Compute Engine supplies the Linux machine; you install and maintain the web, database, and PHP layers yourself. The same pattern works for other distributions, but package names and commands can differ.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does LAMP mean on a Google Cloud server?

LAMP is a four-layer web application stack: Linux provides the operating-system foundation, Apache accepts and serves HTTP requests, MySQL stores relational data, and PHP generates dynamic pages. The “P” can also refer to Perl or Python, but this installation uses PHP.

Compute Engine gives you an ordinary Linux virtual machine that you can administer like a physical server. Google Cloud does not automatically install Apache, MySQL, or PHP when you create the VM. You select an operating-system image, then install the remaining layers through that image’s package manager.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

A request normally follows this path: a browser resolves your domain to the VM’s external address, Google Cloud’s VPC firewall evaluates the connection, Apache receives TCP traffic on port 80 or 443, PHP processes application code, and MySQL supplies or stores data. Each layer has a separate failure mode, so troubleshooting is easier when you test them in that order.

What do I need before creating the VM?

You need a Google Cloud account, a project with billing enabled, permission to create Compute Engine resources, and a domain only if you want public DNS immediately. Compute Engine resources are billable; the machine type, disk, external address, and network traffic determine the current charge, so review the estimates shown in the Cloud Console before creating the VM.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose an Ubuntu LTS image

For a current long-lived deployment, select an Ubuntu LTS image rather than an end-of-life release. Google Cloud’s operating-system list currently shows Ubuntu 24.04 LTS with general support through June 2029 and extended security maintenance (ESM) through April 2034. Ubuntu 22.04 LTS is listed with general support through April 2027 and ESM through April 2032. Confirm the image’s status and support dates in the console because image catalogs change.

Choose a machine size deliberately

A small shared-core machine can be suitable for a personal site, staging, or a low-traffic proof of concept, but PHP workers, MySQL memory use, backups, and monitoring all compete for resources. The older Google-contributed LAMP tutorial used an e2-micro example and was published on February 15, 2017; treat that machine choice as historical context, not a current performance recommendation. Select the smallest current machine that meets your workload, then watch memory, CPU, disk, and request latency before resizing.

How do I create an Ubuntu Compute Engine VM?

Use the Cloud Console to create a Linux VM, select an Ubuntu LTS image, and expose only the traffic you are ready to serve. The exact machine and pricing choices are region-dependent and can change, so use the values currently displayed in your project.

  1. Open Google Cloud Console, select an existing project or choose New project, and enable billing for that project.
  2. Open Compute Engine → VM instances and select Create instance.
  3. Choose a region and zone close to your users or dependent services. Pick an Ubuntu 24.04 LTS or 22.04 LTS image from the boot-disk options.
  4. Choose a machine type and boot-disk size appropriate for the workload. Leave room for operating-system updates, logs, uploaded files, and database growth.
  5. Under the network or firewall options, enable Allow HTTP traffic. Enable Allow HTTPS traffic when you are ready to configure TLS; enabling the checkbox alone does not create a certificate or an HTTPS virtual host.
  6. Create the instance and wait until its status is running. Record its external IP address, but remember that an automatically assigned address can be ephemeral.

The HTTP checkbox creates or applies a VPC firewall rule using the VM’s network tag. If you later change tags, networks, or firewall rules, verify that the rule still targets this instance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do Google Cloud firewall rules and the VM firewall work together?

Both layers must permit a connection. Google Cloud always enforces enabled VPC firewall rules, regardless of the guest operating system’s configuration or whether the VM has started. A UFW rule inside Ubuntu cannot compensate for a missing VPC ingress rule.

Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Required ports

Purpose Protocol and port When to allow it Security note
HTTP TCP 80 During initial testing and for sites intentionally serving plain HTTP or redirecting to HTTPS Public web traffic is expected; do not treat port 80 as encrypted.
HTTPS TCP 443 After a certificate and Apache TLS virtual host are configured Opening the port before TLS is configured does not make the site secure.
SSH administration TCP 22 Only from trusted administration paths Restrict source ranges or use an approved identity-based access method.
MySQL TCP 3306 Normally not from the public internet Keep the database private and let the application connect locally.

If you create custom rules, target the VM’s network tag and restrict source ranges wherever practical. Keep database ports off public ingress. A connection that times out usually indicates a VPC rule, network tag, route, or guest firewall problem before it indicates a PHP problem.

How do I connect to the VM over SSH?

The simplest method is the SSH button beside the running instance in Compute Engine → VM instances. You can also use the Google Cloud CLI:

gcloud compute ssh VM_NAME --zone=ZONE

Replace VM_NAME and ZONE with the instance name and zone. Prefer OS Login or key-based access, keep administrative accounts separate from application accounts, and avoid exposing SSH to the entire internet. If the Console SSH button fails, check that the VM is running, the account has permission, and port 22 is reachable from your administration path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I install Apache on Ubuntu?

Update the package index, install Apache, and verify that its systemd service is running. Run these commands in the SSH session:

sudo apt update
sudo apt -y install apache2
sudo systemctl status apache2

The status output should show an active service. Apache’s default document root is normally /var/www/html. From a browser outside Google Cloud, request http://EXTERNAL_IP, replacing EXTERNAL_IP with the VM’s current address. You should see the default Apache page if TCP 80 is allowed and the service is healthy.

If the service is inactive, inspect the status output and recent logs before restarting. A configuration syntax error, a port already used by another service, or a failed package installation must be corrected at the cause rather than hidden with repeated restarts.

How do I install MySQL and PHP with Apache?

On Ubuntu, install PHP, Apache’s PHP module, the MySQL server, and the PHP-MySQL connector in one package operation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
sudo apt -y install php libapache2-mod-php mysql-server php-mysql

Package names can vary by distribution release and repository configuration. Confirm the package set for the Ubuntu image you selected before putting this command into automation. The Apache module lets Apache hand .php files to PHP; php-mysql lets PHP applications connect to MySQL.

Check the services after installation

Verify Apache again after the package installation. If you changed Apache modules or virtual-host configuration, restart or reload Apache only after checking its configuration. MySQL may be managed by systemd under a distribution-specific service name; use the service status shown by the package installation and your Ubuntu documentation rather than assuming a custom unit name.

Run the database hardening workflow

Before storing real data, run Ubuntu’s MySQL hardening workflow and review every prompt. Remove anonymous accounts and test databases where appropriate, prevent remote administrative login, and create an application database user with only the permissions that application requires. Do not publish port 3306 merely to make administration convenient; use a private connection or a controlled administrative tunnel.

How do I verify PHP through Apache?

Use a temporary phpinfo() file to prove that Apache is executing PHP rather than downloading the source. Create it, request it through the VM’s external IP, and remove it immediately after the check:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
echo '<?php phpinfo();' | sudo tee /var/www/html/info.php
curl http://EXTERNAL_IP/info.php
sudo rm /var/www/html/info.php

Replace EXTERNAL_IP with the current address. The curl response should contain rendered PHP configuration output, not the literal PHP source and not a file download. The page exposes detailed environment information, so never leave it online.

For a safer application check, replace the default document with a minimal index file owned by the account or deployment process that needs to modify it. Keep Apache’s system directories protected, and avoid giving the web server unrestricted write access to the entire document root.

Test HTTP before TLS

Use http://EXTERNAL_IP for the first end-to-end test. Do not switch to https:// until a certificate, Apache SSL module, and TLS virtual host are configured. An HTTPS browser error at this stage is expected, not evidence that Apache or PHP is broken.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

How do I assign a static external IP and connect DNS?

Compute Engine external addresses can be ephemeral or static. An ephemeral address may change when you stop and recreate a VM, which can break DNS records, allowlists, webhooks, or other integrations. Reserve and attach a static external IP when clients need a fixed address.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. In the Cloud Console, open the external-IP address management page for your project and reserve a regional address that matches the VM’s region.
  2. Assign that reserved address to the VM’s network interface, following the console’s confirmation prompts.
  3. Confirm the VM now reports the reserved address and test http://STATIC_IP.
  4. At your DNS provider, point the domain’s A record to the static IPv4 address. Add an AAAA record only if you have deliberately configured IPv6 on the VM and firewall.
  5. After DNS propagation, configure Apache’s virtual host with the intended hostname and test both the hostname and the direct address.

Reserve the address before publishing DNS, and release unused static addresses so they do not remain attached to the project unnecessarily. DNS cannot fix a missing VPC rule or an Apache virtual-host error.

How do I add HTTPS for a production site?

HTTPS requires more than opening TCP 443. Obtain a certificate for the domain, configure Apache’s SSL support and a TLS virtual host, install the certificate and private key with restrictive permissions, and then allow TCP 443 in the VPC firewall. Redirect HTTP to HTTPS only after the HTTPS hostname works.

Certificate issuance normally requires that the domain resolve to the VM and that the validation method can reach the server. Renew certificates before expiry, test renewal in a staging or non-production path when possible, and monitor for failed renewals. Keep private keys out of the web root and out of source-control repositories.

What production hardening should I complete?

A working LAMP page is an installation milestone, not a production security review. Apply controls that match your application, organization, and compliance requirements.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Least privilege: use separate SSH identities, avoid daily work as root, give the PHP application only the database permissions it needs, and keep deployment credentials distinct from runtime credentials.
  • Patch management: apply Ubuntu security updates, PHP updates, Apache updates, and MySQL updates on a schedule. Test major-version changes before applying them to the production VM.
  • Network isolation: allow HTTP and HTTPS publicly as required, restrict SSH to trusted administration sources, and keep MySQL private. Use separate tiers or private networking when the application grows beyond one VM.
  • Backups: back up database data, uploaded files, configuration, and encryption keys according to a documented retention policy. Test restoration; an untested backup is not a recovery plan.
  • Monitoring: watch uptime, CPU, memory, disk space, Apache errors, PHP errors, MySQL health, certificate expiry, and backup success. Set alerts before the disk fills or a service stops.
  • Secrets: store database passwords and API credentials outside publicly served files, restrict file permissions, and rotate credentials after staff or systems change.
  • Application controls: configure secure cookies, input validation, dependency updates, upload limits, and a deployment rollback process in the application itself.

Google’s basic Apache instructions establish installation and network behavior, but they do not certify a universal production-hardening recipe. Adapt the controls to your threat model and operational responsibilities.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why does my Google Cloud Apache page not load?

Check the path from the client to the service in order: DNS or IP address, VPC firewall, VM network tag, guest firewall, Apache service, virtual-host configuration, and finally the application.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Symptom Check first Likely correction
Browser times out VPC firewall rule, VM network tag, Apache status Permit TCP 80, and TCP 443 only after TLS is configured; then check or restart Apache.
Default Apache page appears but your site does not Document root, enabled virtual host, hostname resolution Place the application in the configured document root, enable the intended virtual host, and verify DNS points to this VM.
PHP downloads or appears as text libapache2-mod-php, Apache module, file extension Install the Apache PHP module, restart or reload Apache, and use a file ending in .php.
Site worked, then DNS stopped resolving Whether the VM address is ephemeral Reserve and attach a static external IP, then update the DNS A record.
SSH is exposed broadly VPC and guest firewall source ranges Restrict SSH to administration sources and do not open database ports publicly.
https:// fails while http:// works Certificate, Apache SSL module, TLS virtual host, TCP 443 rule Complete certificate and TLS configuration, then allow TCP 443.

Use service status and logs to distinguish a network timeout from an application error. A successful local request from the VM combined with a failed external request points toward VPC rules, routes, tags, DNS, or the guest firewall.

Should I self-manage LAMP on Compute Engine or use managed services?

A single Compute Engine VM gives maximum control and can be economical for a small, conventional application, but you own patching, backups, failover, and incident response. Managed components shift some operational work to the provider, usually with different pricing, configuration limits, and migration considerations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision factor Self-managed LAMP on one VM Managed database or higher-level service
Operational control Full control of the operating system, Apache, PHP, and MySQL configuration. Less host-level control; service settings are constrained by the product.
Patching responsibility You schedule and verify operating-system, web-server, PHP, and database updates. The provider handles some platform maintenance; you still manage application compatibility and settings.
Backups and failover You design, pay for, monitor, and test backups and recovery. Backup and failover features may be available, but retention, recovery objectives, and pricing must be checked for the chosen service.
Network isolation You design VPC rules, private paths, and host firewalls. Service networking can simplify isolation but introduces product-specific controls.
Predictable cost VM, disk, address, traffic, and operations costs are directly tied to your configuration; current pricing must be checked. Service tiers, storage, operations, and transfer charges vary; no universal price applies.
Migration effort Portable Linux packages and files, but you must migrate the entire host. Less host maintenance, but migration may require adapting schemas, extensions, or connection methods.
Best fit Learning, prototypes, small sites, and applications needing one-server control. Multi-tier production systems where managed availability or reduced database administration justifies the trade-off.

Choose based on your recovery objectives and staff capacity, not only the initial VM size. A one-VM LAMP stack is a valid starting architecture, but it is a single failure domain until you add redundancy and tested recovery.

What ongoing maintenance does a LAMP VM require?

Schedule maintenance instead of waiting for an outage. Review this checklist after deployment and at the interval appropriate for your risk profile:

  • Confirm Apache, PHP, and MySQL are running and serving the expected virtual host.
  • Apply security updates and review reboot requirements.
  • Check disk growth, database size, log rotation, and inode usage.
  • Verify backups completed and perform periodic restoration tests.
  • Review VPC firewall rules, SSH source ranges, service accounts, and unused static addresses.
  • Test certificate renewal and check certificate expiration dates.
  • Review application and dependency updates in a staging environment before production rollout.
  • Record the VM image, zone, static IP, DNS records, package versions, and recovery procedures so another administrator can rebuild the service.

Frequently Asked Questions

Can I install LAMP on Debian instead of Ubuntu on Compute Engine?

Yes. Compute Engine supports multiple Linux images, and the architecture remains Linux, Apache, MySQL, and PHP. Use the selected distribution’s package names, service-management conventions, and security-update process rather than copying Ubuntu commands unchanged.

Will stopping my VM change its external IP address?

An ephemeral external address can change when the VM lifecycle changes, which can break DNS and allowlists. Reserve and attach a static external IP whenever a domain or integration requires a stable address.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do I need a domain name to test the installation?

No. You can test Apache and PHP with the VM’s external IP over HTTP. A domain becomes necessary for normal hostname-based virtual hosts, public certificate issuance, and production DNS.

Can I expose MySQL so a desktop client can connect directly?

Avoid public database exposure for routine administration. Keep MySQL on a private interface or localhost and use a controlled administrative tunnel or private network path, with restricted accounts and encryption where applicable.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

ApacheCompute EngineDevOpsGoogle CloudLAMPMySQLPHPUbuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.