How to Edit php.ini on a Google Cloud VM (Debian and Ubuntu)

Quick Summary

  • Connect to the Compute Engine VM with the SSH button on the VM instances page or gcloud compute ssh, then run ls /etc/php/*/*/php.ini to see the PHP versions and files.
  • Edit the file your site's PHP loads, /etc/php/X.Y/fpm/php.ini for PHP-FPM or /etc/php/X.Y/apache2/php.ini for mod_php; the cli file only affects the php command.
  • Keep post_max_size larger than upload_max_filesize, restart phpX.Y-fpm or apache2, and on Nginx raise client_max_body_size too, since it blocks uploads over 1 MB by default.

To edit php.ini on a Google Cloud Compute Engine VM, connect to the VM over SSH, find the php.ini that your website’s PHP loads, edit it with sudo nano and restart PHP-FPM or Apache. On the Debian and Ubuntu images, every PHP version has its own folder under /etc/php/, with one php.ini per way of running PHP: fpm/php.ini for PHP-FPM, apache2/php.ini for Apache’s mod_php and cli/php.ini for the command line. The steps below work for any PHP version; replace 8.4 in the examples with yours.

Connect to the VM over SSH

  1. In the Google Cloud console, open your project and go to Compute Engine > VM instances. Screenshot: the VM instances page (an older console layout: the page looks different today, but the SSH button is still in the VM’s row)
  2. Click SSH in your VM’s row. Screenshot: the SSH button
  3. SSH-in-browser opens a terminal on the VM in a new window. Screenshot: the SSH window

You can also connect from your own computer with the Google Cloud CLI (Google’s SSH guide covers both ways):

Shell
gcloud compute ssh VM_NAME --zone=ZONE

Which php.ini does your site use?

First see which PHP versions and php.ini files the VM has:

Shell
php -v
ls /etc/php/*/*/php.ini

php -v prints the command-line PHP version. The second command lists one php.ini per PHP version and folder, for example /etc/php/8.4/cli/php.ini and /etc/php/8.4/fpm/php.ini. If you installed PHP from the image’s own packages, the version depends on the image: PHP 8.4 on Debian 13, 8.2 on Debian 12, 8.5 on Ubuntu 26.04 LTS, 8.3 on Ubuntu 24.04 LTS and 8.1 on Ubuntu 22.04 LTS.

The folder tells you who reads the file:

  • fpm: PHP-FPM, the separate PHP service that Nginx uses, and Apache too when it’s set up with PHP-FPM.
  • apache2: mod_php, PHP running inside Apache.
  • cli: only the php command, such as cron jobs, WP-CLI and Composer. Changing it doesn’t change your website.

php --ini shows the file the command line loads (“Loaded Configuration File”) and its extra configuration folder (“Scan for additional .ini files in”). To be sure which file the website loads, ask the web server’s PHP. Create a temporary file in your web root, for example /var/www/html/ini-check.php:

PHP
<?php
header( 'Content-Type: text/plain' );
echo php_sapi_name(), "\n";
echo php_ini_loaded_file(), "\n";
echo php_ini_scanned_files(), "\n";
echo 'upload_max_filesize = ', ini_get( 'upload_max_filesize' ), "\n";
echo 'post_max_size = ', ini_get( 'post_max_size' ), "\n";
echo 'memory_limit = ', ini_get( 'memory_limit' ), "\n";

Open https://your-domain/ini-check.php. The first line is fpm-fcgi for PHP-FPM or apache2handler for mod_php, the second is the php.ini path, then come the extra .ini files and the current limits. Delete the file when you’re done, since it tells visitors about your setup: sudo rm /var/www/html/ini-check.php. On a WordPress site you can skip the file: Tools > Site Health > Info > Server shows the PHP SAPI and the limits.

The original version of this step searched the whole disk with sudo find / -name "php.ini". That still works, and it also finds copies outside /etc/php/, for example from a PHP that wasn’t installed with apt. If php --ini or the check file names such a file, edit that one.

Change the values

Open the file as root in the nano editor. sudo is enough; you don’t need to switch to the root user with sudo -i first:

Shell
sudo nano /etc/php/8.4/fpm/php.ini

Press Ctrl+W to search for each setting, change its value and make sure the line doesn’t start with a semicolon, which turns it into a comment. For example, to allow uploads of up to 256 MB:

Code
upload_max_filesize = 256M
post_max_size = 300M
memory_limit = 256M
  • upload_max_filesize is the largest single file PHP accepts.
  • post_max_size is the largest whole request, all files and form fields together. The PHP manual says it must be larger than upload_max_filesize. If a request is bigger, PHP leaves $_POST and $_FILES empty.
  • memory_limit is the memory one PHP script may use. Raise it when you see “Allowed memory size of … bytes exhausted”.

Save with Ctrl+O and Enter, and exit with Ctrl+X. If a setting appears twice, the last line wins.

Instead of editing php.ini, you can put your changes in a file of their own. PHP reads every .ini file in the conf.d folder after php.ini, in alphabetical order, so a file named 99-custom.ini overrides the same settings in php.ini, and php.ini stays as the package installed it:

Shell
sudo nano /etc/php/8.4/fpm/conf.d/99-custom.ini

Put the same three lines in it and save.

Restart PHP-FPM or Apache

The web server’s PHP reads its configuration when it starts, so restart the service that runs it. For PHP-FPM, use the service of your PHP version:

Shell
sudo systemctl restart php8.4-fpm

With mod_php, restart Apache instead: sudo systemctl restart apache2. The php command reads its php.ini every time it runs, so command-line changes apply at once. To check them:

Shell
php -i | grep -E 'upload_max_filesize|post_max_size|memory_limit'

Each line shows the setting twice, for example upload_max_filesize => 256M => 256M. These are the command-line values; for the website, open the check file again or look at Tools > Site Health > Info > Media Handling in WordPress, which shows the maximum upload size.

Why doesn’t my change show up?

  • You edited another file. The cli file, or the file of a PHP version the site doesn’t use, has no effect on the website. The check file shows the right one.
  • The service wasn’t restarted, or you restarted the PHP-FPM service of another version. systemctl list-units 'php*-fpm*' lists the ones that exist.
  • Nginx rejects the upload first. Nginx accepts request bodies of up to 1 MB by default and answers larger ones with “413 Request Entity Too Large” before PHP sees them. Add client_max_body_size 300m; to your site’s server block, then run sudo nginx -t and sudo systemctl reload nginx. See client_max_body_size in the Nginx docs.
  • PHP was upgraded. A new PHP version reads its own folder, for example /etc/php/8.4/ instead of /etc/php/8.2/, so make your changes again there. Installing and upgrading PHP on Debian covers the switch.

Video: How to Increase File Upload Size WordPress on Google Cloud (YouTube)

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)