A Bash script for updating installed PHP versions affected by the October 2026 PHP security vulnerabilities.
The script follows Laravel Forge's official manual SSH guidance:
https://laravel.com/forge/docs/knowledge-base/php-security-release-october-2026#manually-via-ssh
The script:
- Detects the Ubuntu version.
- Checks the PHP package repository configuration.
- Repairs the old Ondrej PHP repository on supported Forge servers.
- Creates a backup before changing the repository.
- Runs
apt-get updateand stops if the package lists cannot be updated successfully. - Detects all installed PHP versions.
- Checks the currently installed PHP version.
- Checks whether the required patched version is available from APT.
- Only upgrades PHP packages that are already installed.
- Preserves existing PHP configuration files.
- Verifies the installed PHP version after upgrading.
- Skips versions where the security update is not yet available.
- Warns about unsupported PHP versions.
PHP Patched version
PHP 8.2 8.2.35 PHP 8.3 8.3.36 PHP 8.4 8.4.27 PHP 8.5 8.5.12
PHP 8.1 and earlier do not have a security fix for these vulnerabilities and should be upgraded separately.
Laravel Forge's current guidance uses different PHP package sources depending on the Ubuntu version.
The script expects:
/etc/apt/sources.list.d/ondrej-php.list
If the PHP repository is still using:
ppa.launchpadcontent.net/ondrej/php
the script automatically changes it to:
ppa.setup-php.com
Before making the change, a timestamped backup of the existing source file is created.
For example:
/etc/apt/sources.list.d/ondrej-php.list.bak.20261021163000
If the server is already using ppa.setup-php.com, no changes are made.
The script expects:
/etc/apt/sources.list.d/php.list
using:
packages.sury.org/php
The script verifies this configuration but does not attempt to automatically repair an unexpected Ubuntu 26.04 repository.
If the PHP repository exists but is in an unexpected format, the script stops rather than attempting to modify it.
If the expected PHP source file is completely missing, the script also stops.
In these cases, Laravel Forge recommends repairing the PHP package source through the Forge dashboard.
After checking the PHP repository, the script runs:
apt-get updateIf this command fails, the script stops immediately.
This is important because continuing with stale package indexes could result in the script incorrectly determining that a security update is unavailable.
The script will not continue with PHP package upgrades until APT can successfully refresh the package lists.
Download or copy the Bash script onto your server.
Make it executable:
chmod +x php-security-update.shRun it as root:
sudo ./php-security-update.shFor each installed PHP version, the script determines which PHP packages are already installed.
It then uses:
apt-get install --only-upgrade -yThis means the script only upgrades existing packages rather than deliberately installing additional PHP packages.
It also uses:
-o Dpkg::Options::="--force-confold"This tells Debian/Ubuntu package management to retain existing configuration files when an updated package contains a different version of the same configuration file.
Before upgrading PHP, the script checks the package candidate available through APT.
For example:
Current: 8.4.26
Required: 8.4.27
Package candidate: 8.4.27-1+ubuntu24.04.1+deb.sury.org+1
Candidate PHP version: 8.4.27
The upgrade only proceeds if the candidate PHP version is equal to or newer than the required security release.
If the patched package has not reached the configured repository yet, that PHP version is skipped.
After upgrading, the script checks the installed PHP version again.
For example:
Installed: 8.4.27
Required: 8.4.27
PHP 8.4 successfully patched.
If the resulting version does not meet the minimum patched version, the script reports an error and stops.
The script does not automatically migrate applications from PHP 8.1 or earlier to PHP 8.2+.
Changing the PHP major/minor version used by an application can introduce compatibility issues and should be handled and tested separately.
If an unsupported PHP version is detected, the script warns you but does not modify it.
After updating PHP, you may need to restart application processes that remain resident in memory, including:
- Laravel queue workers
- Laravel Horizon
- Laravel Octane
- Laravel Reverb
- Supervisor-managed PHP processes
These are application-specific, so the script deliberately does not attempt to restart them automatically.
The PHP repository repair only applies to the PHP package source documented by Laravel Forge.
It does not modify unrelated repositories such as:
ppa.launchpadcontent.net/laravelphp/forge
If another repository is unavailable and causes apt-get update to
fail, the script will stop rather than continue using potentially stale
package information.
Run the script on one non-critical server first and confirm that its websites and applications are operating correctly before using it across multiple production servers.
Ensure appropriate backups are available before performing system package upgrades.
Laravel Forge - PHP Security Release October 2026:
https://laravel.com/forge/docs/knowledge-base/php-security-release-october-2026#manually-via-ssh
This script is provided as a convenience for applying the October 2026 PHP security updates to Laravel Forge servers.
Review and test the script against your own server configuration before running it in production.