Halloween 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 NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › Apache

Install PHP on a Google Cloud VM: Apache and NGINX Setup

By Freedom251 Team · · 7 min read

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.

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 PHP on a Google Cloud server, create an Ubuntu Compute Engine VM, install PHP and the integration required by your web server, then verify the site from the VM’s external IP. Apache uses the libapache2-mod-php package; NGINX uses PHP-FPM and FastCGI configuration. For public HTTP access, the VM also needs an external IP and a Google Cloud firewall rule allowing TCP port 80.

What does installing PHP on a Google Cloud server involve?

Google Cloud Compute Engine provides the virtual machine; Ubuntu supplies PHP and web-server packages. PHP is a general-purpose scripting language suited to web development, and its scripts can be embedded in HTML. Installing PHP alone does not complete a web deployment: the web server must be connected to PHP, and the application may need additional PHP extensions or database drivers.

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.

The setup has four decisions: choose a supported Ubuntu image, select Apache or NGINX, install the PHP packages your application needs, and decide whether the site should be reachable from the public internet. You can install packages manually over SSH or use a Compute Engine startup script to repeat a setup.

Which Ubuntu image should I choose?

Google Cloud lists Ubuntu 24.04 LTS and Ubuntu 22.04 LTS images in the ubuntu-os-cloud project. Confirm image availability and lifecycle dates in the image catalog when creating a VM; images and package versions can change over time.

#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.

Use an Ubuntu release supported by your application and deployment plan. The listed image versions are not a promise that every PHP release or extension is available in every repository at every future date. Check the package and image state at deployment time rather than assuming a version from an older guide still applies.

What should I prepare in Google Cloud before installing PHP?

Create or select a Google Cloud project, enable billing, and enable the Compute Engine API. Google Cloud’s Compute Engine tutorial describes getting started by deploying a Hello World PHP web app to a VM. You can work in Cloud Shell or connect to the VM over SSH.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • A Google Cloud project with billing enabled.
  • The Compute Engine API enabled for the project.
  • An Ubuntu VM in the project.
  • A decision about Apache or NGINX, based on your application and existing deployment requirements.
  • The PHP extensions or database drivers the application actually requires.
  • An external IP and a TCP port 80 firewall rule if you intend to test public HTTP access.

How do I install PHP with Apache?

On the Ubuntu VM, update the package index and install PHP with Apache’s PHP module. Add command-line, CGI, or database packages only if the workload needs them.

  1. Connect to the VM. Open an SSH session from Google Cloud or use another SSH method configured for the instance.
  2. Refresh Ubuntu’s package index: sudo apt update.
  3. Install Apache’s PHP integration: sudo apt install php libapache2-mod-php.
  4. Add only required packages. For command-line PHP, add php-cli; for CGI, add php-cgi. For MySQL or PostgreSQL database support, add php-mysql or php-pgsql, respectively.
  5. Restart Apache: sudo systemctl restart apache2.service.
  6. Verify PHP through the web server. Create a temporary phpinfo.php file in the web root containing a PHP phpinfo() call, then request that file using the VM’s external IP.

Apache’s integration package is libapache2-mod-php. Do not assume that installing an extra PHP package is necessary: select extensions and interfaces according to the application’s documented dependencies.

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.

How do I install PHP with NGINX?

NGINX does not use Apache’s libapache2-mod-php integration path. Install NGINX, PHP-FPM, and the extensions required by the application, then configure NGINX to send PHP requests to PHP-FPM using FastCGI.

Google Cloud’s Compute Engine sample startup script illustrates a repeatable approach: it updates packages, installs PHP-FPM and extensions, installs Composer, copies an NGINX configuration, and restarts NGINX. Use the sample configuration and script as the basis for your application-specific setup, checking that the PHP-FPM service and FastCGI settings match the installed packages and configuration. The exact configuration is not interchangeable with Apache’s PHP module setup.

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

For a one-off VM, you can perform these tasks manually over SSH. For a setup that needs to be recreated, a startup script can keep installation of PHP, the web server, Composer, and application setup in one repeatable process. Review what the script installs and configures before using it on your VM.

Which packages and integration path should I use?

Choose packages based on the server and application rather than installing every available PHP interface. The package names below correspond to the installation paths and optional dependencies described for Ubuntu.

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.
Need Package or integration When to use it
PHP with Apache php and libapache2-mod-php When Apache will serve the site and execute PHP through its module.
PHP command-line interface php-cli When the application or your administration workflow needs PHP from the command line.
PHP CGI interface php-cgi When the workload specifically requires CGI.
MySQL database driver php-mysql When the PHP application needs MySQL support.
PostgreSQL database driver php-pgsql When the PHP application needs PostgreSQL support.
PHP with NGINX PHP-FPM plus FastCGI configuration When NGINX serves the site and passes PHP requests to PHP-FPM.

The web server and PHP integration are separate parts of the setup. Installing the wrong integration path is a common reason a web server can serve static files but does not execute PHP as intended.

How do I make the VM reachable over HTTP?

For a public HTTP test, the VM needs an external IP and a Google Cloud firewall rule permitting TCP port 80. Without both, requesting the public address is not a valid test of whether PHP itself works.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Confirm the VM has an external IP address.
  2. Create or configure a Google Cloud firewall rule that allows TCP port 80 to the VM. Google Cloud’s example uses gcloud compute firewall-rules create ... --allow tcp:80; replace the ellipsis with the rule details appropriate to your project and target VM.
  3. Open http://YOUR_INSTANCE_IP in a browser, replacing the placeholder with the VM’s actual external IP.
  4. Request the temporary PHP verification file if you are checking PHP execution through the web server.

If you only need private testing, do not treat public exposure as a required part of installing PHP. Keep access limited to the intended audience and only open the ports needed for the test.

How can I verify PHP without leaving a security-sensitive page online?

A temporary phpinfo.php page provides a direct check that the web server executes PHP and reports configuration details. Because those details are exposed to anyone who can reach the page, remove it or protect it once verification is complete.

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
  1. Create the temporary file in the web root with a PHP phpinfo() call.
  2. Request the file through the VM’s external IP, using HTTP only if you have allowed TCP port 80.
  3. Confirm the response is a PHP information page rather than the PHP source being displayed as text or an error page.
  4. Delete the file or restrict access after testing.

A successful response confirms PHP execution for that test page; it does not by itself verify that the application’s required extensions, database connection, or application configuration are correct.

Why might the PHP site fail to load?

Diagnose the layer that is failing: VM access, firewall reachability, web-server integration, PHP execution, or an application dependency. Changing PHP packages will not fix a blocked network path, and opening a firewall port will not correct a missing database driver.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • The external IP does not respond: Check that the VM has an external IP and that a Google Cloud firewall rule allows TCP port 80 for the VM.
  • The site responds but PHP source is shown or PHP is not executed: Confirm the server uses the appropriate integration. Apache requires libapache2-mod-php; NGINX requires PHP-FPM and FastCGI configuration.
  • The web server does not reflect the Apache package change: Restart Apache with sudo systemctl restart apache2.service.
  • The application reports a missing database or PHP feature: Check its dependency requirements and install the matching package, such as php-mysql or php-pgsql when applicable.
  • A package or image is unavailable: Recheck the Ubuntu image catalog and the VM’s current package repositories, since image availability and package versions can change.
  • The temporary PHP test page works but the application does not: The test confirms PHP execution only. Investigate application-specific extensions and configuration separately, and remove or protect the test page.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Should I install packages manually or use a startup script?

Manual SSH installation is direct for a single VM; a startup script is useful when you want a repeatable setup. The choice is operational, not a different PHP runtime: both approaches still need the right web-server integration and application dependencies.

Approach Best fit Trade-off
Manual SSH package installation A single VM or a setup you are configuring interactively. Commands and configuration changes must be repeated deliberately when recreating the server.
Compute Engine startup script A setup you want to repeat, including web server, PHP-FPM, extensions, Composer, and NGINX configuration. The script and copied configuration must match the VM, application, and intended PHP integration.

Google Cloud’s Compute Engine sample startup script provides an example of the NGINX and PHP-FPM route. Do not treat it as a universal application deployment: its packages and configuration need to align with the software you intend to run.

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.

Frequently Asked Questions

Can I install PHP on a Google Cloud VM without Apache or NGINX?

Yes. The web-server integration is needed to serve PHP over HTTP, not to install PHP for command-line use. The package list includes php-cli for workloads that need the command-line interface.

Do I need Composer to install PHP on a Compute Engine VM?

Composer is not part of the basic Apache package command. Google Cloud’s cited NGINX startup-script example installs Composer as part of its broader setup, so whether you need it depends on the application and deployment workflow.

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.

Does opening port 80 make a PHP site secure?

No. A firewall rule controls network reachability; it does not secure the application or replace appropriate access controls. The documented public test is HTTP on port 80, so treat that as a reachability check rather than a complete production security setup.

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 EngineGoogle CloudNGINXPHPUbuntu

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
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.