iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To install PHP on a Google Cloud server, create or select a Compute Engine VM running Ubuntu, connect over SSH, install PHP with either Apache or NGINX, and then test the interpreter through the VM’s web server. Apache loads PHP through libapache2-mod-php; NGINX passes requests to PHP-FPM. For a site that must be reachable from the internet, you also need an external IP address and a Google Cloud firewall rule allowing TCP port 80. Ubuntu 22.04 LTS and 24.04 LTS images are available in the ubuntu-os-cloud project, but image availability and package versions change, so verify the current image catalog and repository state when you deploy.
What do you need before installing PHP on Google Cloud?
You need a Google Cloud project with billing enabled, the Compute Engine API enabled, and permission to create or administer a VM. You can use Google Cloud Shell for gcloud commands and then open an SSH session to the VM, or use the SSH button in the Google Cloud console.
- A project: Create a new project or select an existing one in the Google Cloud console.
- Billing: Compute Engine requires billing to be enabled, even when you intend to use a trial or other credits.
- Compute Engine API: Enable the API before creating the instance.
- An Ubuntu image: Google Cloud currently lists Ubuntu 24.04 LTS and Ubuntu 22.04 LTS images in the
ubuntu-os-cloudproject. Check the image catalog at deployment time because image names, package versions, and support dates change. - A connection method: Cloud Shell, the browser-based SSH button, or an SSH client configured for the VM.
- A web-server decision: Choose Apache for the simplest PHP module integration, or NGINX when you want PHP-FPM and a separate application process.
Keep the first test private if possible. You can install and validate PHP over SSH before opening HTTP to the public internet.
How do you create an Ubuntu Compute Engine VM?
Create the instance in the Google Cloud console or with gcloud, selecting an Ubuntu LTS image and a machine size appropriate for your application. The exact machine types and image labels are revised over time, so select the currently offered Ubuntu image rather than copying an old image name from a guide.
#1 Best Overall
- 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.
Console workflow
- Open Compute Engine in the Google Cloud console and choose VM instances.
- Select Create instance, choose the project and region, and give the VM a recognizable name.
- In the boot-disk section, select an Ubuntu 24.04 LTS or Ubuntu 22.04 LTS image from the
ubuntu-os-cloudimage project. - Choose a machine configuration that fits the expected PHP workload. A development VM and a production application may need very different CPU, memory, disk, and availability settings.
- Decide whether the VM needs an external IPv4 address. A private test can remain reachable only through SSH or an internal network; a public website needs a reachable external address or a load-balancing design.
- Create the instance, wait for its status to become running, and select SSH to open a terminal.
Connect with Cloud Shell or a local SSH client
From Cloud Shell, set the active project and connect with gcloud compute ssh VM_NAME --zone=ZONE, replacing the instance name and zone with the values you selected. The browser SSH button performs the same connection without requiring you to manage a local key. Once connected, commands such as sudo apt update run on the Ubuntu VM, not in Cloud Shell.
Confirm the operating system before installing packages with cat /etc/os-release. This prevents applying instructions for one Ubuntu release to another and gives you a record of the image used.
Should you use Apache or NGINX with PHP?
Both web servers can deliver PHP applications on a Compute Engine VM. Apache embeds PHP through a module, while NGINX forwards dynamic requests to the PHP-FPM service over FastCGI.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →| Decision point | Apache | NGINX |
|---|---|---|
| PHP integration | libapache2-mod-php loads PHP into Apache. |
PHP-FPM handles PHP workers; NGINX uses FastCGI to pass requests to them. |
| Initial installation | Install Apache’s PHP module and restart apache2.service. |
Install NGINX, PHP-FPM, and the extensions your application needs, then configure a FastCGI server block. |
| Configuration style | Common Apache directives and virtual-host files. | Explicit NGINX server blocks and a PHP-FPM socket or listener. |
| Good fit | A straightforward PHP site or an application already documented for Apache. | Sites that need a separate PHP process manager, a high-performance static-file front end, or an existing NGINX layout. |
| Automation | Can be installed manually or in a startup script. | Google’s Compute Engine PHP sample uses a startup script to install PHP-FPM and extensions, install Composer, write an NGINX configuration, and restart NGINX. |
Do not install both web-server integrations just to experiment on the same port. Pick one service to own HTTP, or deliberately configure separate ports while testing.
How do you install PHP with Apache on Ubuntu?
For Apache, install the PHP interpreter and Apache module with APT, add only the interfaces your application requires, restart Apache, and test a small PHP file.
- Refresh package metadata: run
sudo apt update. - Install Apache’s PHP integration: run
sudo apt install php libapache2-mod-php. If Apache is not already present, APT installs it as a dependency. - Add workload-specific packages: install
php-clifor command-line scripts,php-cgiwhen a CGI interface is required,php-mysqlfor MySQL-compatible database drivers, orphp-pgsqlfor PostgreSQL. Install only the drivers and extensions used by the application. - Restart Apache: run
sudo systemctl restart apache2.service. - Check the service: run
sudo systemctl status apache2.service --no-pager. A running service should show an active state; pressqto leave the status view.
Find the Apache document root
A default Ubuntu Apache virtual host commonly serves files from /var/www/html, but an existing image or site may use another path. Inspect the active virtual-host configuration, such as /etc/apache2/sites-enabled/000-default.conf, and use the directory shown by its DocumentRoot directive. Place your test file in that directory rather than assuming the default.
Rank #2
- 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.
Create a temporary PHP test
In the document root, create a file named phpinfo.php containing:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11<?php
phpinfo();
?>
For the default document root, one way to create it is echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/phpinfo.php. Request http://EXTERNAL_IP/phpinfo.php from a browser after HTTP access is allowed. The page should display PHP’s configuration information, proving that Apache is executing PHP rather than returning the source code.
Delete the file immediately after verification with sudo rm /var/www/html/phpinfo.php, or protect it behind authentication. A phpinfo page reveals PHP versions, loaded modules, paths, environment values, and other configuration details that help an attacker profile the server.
How do you install PHP-FPM with NGINX?
NGINX does not execute PHP itself. Install PHP-FPM and the required extensions, identify the FPM socket created by Ubuntu, and configure NGINX to send only PHP requests to that socket.
- Refresh package metadata: run
sudo apt update. - Install the web server and PHP-FPM: run
sudo apt install nginx php-fpm. Add packages such asphp-cli,php-mysql, orphp-pgsqlwhen the application needs them. - Enable and start services: run
sudo systemctl enable --now nginxandsudo systemctl enable --now php*-fpmonly if your shell expands the wildcard to the installed service. If it does not, list the installed service withsystemctl list-unit-files | grep fpmand enable the versioned unit shown there. - Locate the FPM socket: run
ls -l /run/php/. Ubuntu normally creates a versioned socket whose name reflects the PHP release. Use the exact socket path returned on your VM; do not assume that a path from another Ubuntu image exists. - Create or edit an NGINX server block: set the site root to your application directory, route
index.php, and include a PHP location withfastcgi_pass unix:/run/php/ACTUAL_SOCKET_NAME;, replacing the text with the filename you found in/run/php. The block should also include the standard FastCGI parameter include supplied by the Ubuntu NGINX package. - Validate and reload: run
sudo nginx -t. Only when the test reports a valid configuration should you runsudo systemctl reload nginx.
The socket name is tied to the installed PHP release, which is why copying an old NGINX configuration can produce a 502 error after an Ubuntu image or PHP package update. Recheck the socket whenever you change the PHP version.
Recommended Free Tools
Test PHP through NGINX
Place a temporary phpinfo.php file in the configured site root with the same phpinfo() contents used for Apache. Request it through the VM’s address, confirm that the page is generated, and remove it immediately. If the browser downloads the PHP source, the PHP location block is not being matched; if NGINX returns a 502 response, inspect the FPM service and socket path.
Rank #3
- 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.
How do you make the PHP site reachable over HTTP?
Installing PHP does not automatically expose the VM. Public testing requires a network path to the instance, an external IP address, and a Google Cloud VPC firewall rule that permits TCP port 80.
- In the VM details, note the instance’s current external IPv4 address. Treat an ephemeral address as changeable; use a reserved static address when DNS or a long-lived production endpoint depends on it.
- Create or adjust an ingress firewall rule for the VM’s network. A basic rule can be created from Cloud Shell with
gcloud compute firewall-rules create allow-http --allow tcp:80. In a shared or production network, scope the rule with the appropriate network, target tags, or service account instead of opening every instance indiscriminately. - Confirm that the operating-system firewall, if enabled, also allows port 80. The Google Cloud rule controls the VPC edge; it does not override a local firewall policy.
- Open
http://EXTERNAL_IP/in a browser. Use HTTP for this initial test unless you have already configured TLS and a domain name.
If the request times out, check the external address and VPC rule before changing PHP. If you receive an HTTP response but PHP fails, the network path is working and the remaining issue is the web-server or FPM configuration.
How can you automate the installation with a Compute Engine startup script?
A startup script makes a VM build repeatable: on boot it can update APT metadata, install PHP, install the selected web server and extensions, install Composer, write the web-server configuration, and restart services. This is useful when replacing instances or creating multiple environments, but the script must be maintained as Ubuntu images and package names evolve.
In the VM creation screen, place a Bash script in the instance’s Management or Automation startup-script field. A minimal NGINX-oriented foundation is:
#!/bin/bash
set -e
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y nginx php-fpm php-cli php-mysql composer
systemctl enable --now nginx
systemctl enable --now php*-fpm
The wildcard in the final command may expand differently depending on the installed service name. For a production script, discover the exact FPM unit or explicitly select the PHP release supplied by the image repository, then write an NGINX server block whose fastcgi_pass points to the socket created on that VM. Add your application deployment, permissions, and configuration as separate, repeatable steps.
Make startup automation safe to rerun
- Use noninteractive APT options so the boot process does not wait for a prompt.
- Check whether a configuration file already exists before overwriting it.
- Run
nginx -tbefore reloading NGINX. - Keep secrets out of the script; retrieve them from an approved secret-management system instead of embedding passwords.
- Review startup logs in the VM’s serial output or system logs when a build fails. A VM can be running while a later script command has stopped with an error.
What should you check when PHP installation fails?
Most failures fall into package, service, web-server, or network layers. Diagnose the layer that is failing instead of reinstalling everything.
Rank #4
- 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
APT cannot find a package or returns repository errors
Run sudo apt update again and read the repository error. Confirm the VM has outbound network access and that the Ubuntu release is supported by its configured repositories. Package names and available PHP extensions vary by Ubuntu release; use apt-cache policy php and apt-cache search '^php-' to see what the current repositories provide.
Apache will not start
Run sudo apachectl configtest to identify a syntax error, then inspect sudo journalctl -u apache2.service -n 50 --no-pager. A port conflict usually means another service already owns port 80. Stop the unused web server or move one service to a different port rather than running two listeners on the same address.
NGINX returns 502 Bad Gateway
Check that the PHP-FPM unit is active with systemctl status php*-fpm, verify the socket filename in /run/php, and compare it with the fastcgi_pass directive. Also inspect sudo journalctl -u nginx -n 50 --no-pager and the FPM journal. A stale versioned socket path is common after changing Ubuntu images or PHP packages.
The browser shows PHP source code or downloads the file
Apache may not have loaded libapache2-mod-php, or NGINX may lack a matching PHP location block. Recheck the active virtual host, run nginx -t when using NGINX, and make sure the request is reaching the intended document root.
The site works locally but not from the internet
Test from the VM with curl http://127.0.0.1/ to separate application problems from connectivity problems. Then verify the VM’s external IP, the Google Cloud TCP 80 firewall rule, any target-tag or service-account selector, and the local operating-system firewall. A private VM without an external address cannot be reached directly from the public internet.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteWhat should you secure after PHP is working?
Remove diagnostic files, install only required extensions, and avoid treating a successful phpinfo page as a production configuration. Keep Ubuntu and PHP packages patched through the normal APT update process, restrict administrative SSH access, and expose only the ports the application needs. For a public site, plan HTTPS, a domain name, backups, monitoring, and a method for replacing the VM without losing application data.
Best Value
- 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.
Record the Ubuntu image, PHP package release, enabled extensions, web-server configuration, and firewall rules used for the build. This record makes a manually configured VM reproducible and gives you a safe baseline for a startup script or infrastructure-as-code deployment.
Which installation path should you choose?
- Choose Apache when the application expects Apache conventions and you want the shortest path from Ubuntu packages to a working PHP page.
- Choose NGINX with PHP-FPM when you need a separate PHP worker service, an existing NGINX architecture, or explicit control over FastCGI routing.
- Choose a startup script when the VM will be rebuilt, scaled, or handed to another administrator. Test the script against the exact Ubuntu image you intend to deploy.
- Stay private during setup when you are only validating PHP. Add the external IP and TCP 80 rule when a public HTTP endpoint is genuinely required.
The finished setup is a Compute Engine Ubuntu VM with one active web server, PHP and only the extensions your application needs, a verified service configuration, and a deliberately scoped network rule.
Frequently Asked Questions
Can I run PHP on the VM without installing Apache or NGINX?
Yes. The php-cli package can run scripts and development servers for private testing, but it does not provide a production web-server integration by itself. A public HTTP application still needs a deliberately configured front end such as Apache or NGINX.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →How do I find which PHP version Ubuntu installed?
Run php -v for the command-line interpreter and php -m for loaded modules. For PHP-FPM, inspect the service and socket names under /run/php; those names reveal the release used by the web-server configuration.
Why does a PHP page work over 127.0.0.1 but not by external IP?
That pattern usually means PHP and the web server are healthy while the network path is blocked. Check that the VM has an external address, that a Google Cloud ingress rule allows TCP port 80 for this instance, and that any local firewall permits the same port.
Is the phpinfo page safe to leave online?
No. It exposes detailed runtime and server configuration that is useful for fingerprinting an installation. Use it only for a short verification, then delete it or restrict it to an authenticated administrative path.
Quick Recap
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.
Free tools Windows power users keep installed
One-click scans. No signup required.

