Skip to content

Instantly share code, notes, and snippets.

@mrl22
Last active October 21, 2026 16:12
Show Gist options
  • Select an option

  • Save mrl22/5e01ff5d2bf94adebefc0765fbebc243 to your computer and use it in GitHub Desktop.

Select an option

Save mrl22/5e01ff5d2bf94adebefc0765fbebc243 to your computer and use it in GitHub Desktop.
Laravel Forge - PHP Security Update October 2026 - CVE-2026-109618 / CVE-2026-109619

PHP Security Update - October 2026

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

What it does

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 update and 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.

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

PHP repository repair

Laravel Forge's current guidance uses different PHP package sources depending on the Ubuntu version.

Ubuntu 22.04 and 24.04

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.

Ubuntu 26.04

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.

Unknown repository configurations

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.

APT safety check

After checking the PHP repository, the script runs:

apt-get update

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

Usage

Download or copy the Bash script onto your server.

Make it executable:

chmod +x php-security-update.sh

Run it as root:

sudo ./php-security-update.sh

Package upgrades

For each installed PHP version, the script determines which PHP packages are already installed.

It then uses:

apt-get install --only-upgrade -y

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

Security version check

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.

Verification

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.

Unsupported PHP versions

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.

Long-running PHP processes

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.

Other repository errors

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.

Recommendation

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.

Reference

Laravel Forge - PHP Security Release October 2026:

https://laravel.com/forge/docs/knowledge-base/php-security-release-october-2026#manually-via-ssh

Disclaimer

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.

#!/bin/bash
set -e
echo "========================================"
echo " PHP Security Update"
echo " CVE-2026-109618 / CVE-2026-109619"
echo "========================================"
echo
# Fixed versions from PHP security release
declare -A FIXED
FIXED["8.2"]="8.2.35"
FIXED["8.3"]="8.3.36"
FIXED["8.4"]="8.4.27"
FIXED["8.5"]="8.5.12"
# --------------------------------------------------
# Detect Ubuntu version
# --------------------------------------------------
if [ ! -f /etc/os-release ]; then
echo "ERROR: Unable to determine operating system."
exit 1
fi
. /etc/os-release
UBUNTU_VERSION="${VERSION_ID:-unknown}"
echo "Ubuntu version: $UBUNTU_VERSION"
echo
# --------------------------------------------------
# Check / repair PHP package source
# --------------------------------------------------
echo "Checking PHP package source..."
case "$UBUNTU_VERSION" in
"22.04"|"24.04")
PHP_SOURCE="/etc/apt/sources.list.d/ondrej-php.list"
if [ ! -f "$PHP_SOURCE" ]; then
echo
echo "ERROR: Expected PHP package source is missing:"
echo " $PHP_SOURCE"
echo
echo "Forge recommends repairing this through the control panel:"
echo " Server > Runtime > PHP > Update PHP X.X"
echo
exit 1
fi
# Forge now uses ppa.setup-php.com for Ubuntu 22.04/24.04.
if grep -q "ppa.launchpadcontent.net/ondrej/php" "$PHP_SOURCE"; then
echo "Old Ondrej Launchpad PHP repository detected."
echo "Switching to Forge's recommended ppa.setup-php.com mirror..."
# Backup existing source first
cp "$PHP_SOURCE" "${PHP_SOURCE}.bak.$(date +%Y%m%d%H%M%S)"
sed -i \
's#https\?://ppa\.launchpadcontent\.net/ondrej/php/ubuntu#https://ppa.setup-php.com/ubuntu#g' \
"$PHP_SOURCE"
echo "PHP package source updated."
echo
elif grep -q "ppa.setup-php.com" "$PHP_SOURCE"; then
echo "PHP package source is already using ppa.setup-php.com."
echo
else
echo
echo "WARNING: PHP source exists but is not in a recognised format:"
echo " $PHP_SOURCE"
echo
echo "Contents:"
cat "$PHP_SOURCE"
echo
echo "Stopping rather than modifying an unknown repository."
exit 1
fi
;;
"26.04")
PHP_SOURCE="/etc/apt/sources.list.d/php.list"
if [ ! -f "$PHP_SOURCE" ]; then
echo
echo "ERROR: Expected PHP package source is missing:"
echo " $PHP_SOURCE"
echo
echo "Forge recommends repairing this through:"
echo " Server > PHP > Update PHP X.X"
echo
exit 1
fi
if grep -q "packages.sury.org/php" "$PHP_SOURCE"; then
echo "PHP package source is correctly using packages.sury.org/php."
echo
else
echo
echo "WARNING: Unexpected PHP repository configuration:"
cat "$PHP_SOURCE"
echo
echo "Stopping rather than modifying an unknown repository."
exit 1
fi
;;
*)
echo "WARNING: Ubuntu $UBUNTU_VERSION is not explicitly supported by this script."
echo "Stopping to avoid modifying package sources."
exit 1
;;
esac
# --------------------------------------------------
# Refresh repositories
# --------------------------------------------------
echo "Refreshing package lists..."
echo
# Do not continue if apt update fails.
if ! apt-get update; then
echo
echo "ERROR: apt-get update failed."
echo "PHP packages will NOT be upgraded."
exit 1
fi
echo
echo "Package lists updated successfully."
echo
# --------------------------------------------------
# Detect PHP installations
# --------------------------------------------------
if [ ! -d /etc/php ]; then
echo "ERROR: /etc/php does not exist."
exit 1
fi
PHP_VERSIONS=$(ls /etc/php | grep -E '^[0-9]+\.[0-9]+$' | sort -V)
if [ -z "$PHP_VERSIONS" ]; then
echo "ERROR: No installed PHP versions detected."
exit 1
fi
echo "Installed PHP versions:"
echo "$PHP_VERSIONS"
echo
# --------------------------------------------------
# Update each PHP version
# --------------------------------------------------
for VERSION in $PHP_VERSIONS; do
echo "----------------------------------------"
echo "PHP $VERSION"
echo "----------------------------------------"
if [[ -z "${FIXED[$VERSION]}" ]]; then
echo "WARNING: PHP $VERSION is unsupported."
echo "There is no security fix available for this version."
echo
continue
fi
REQUIRED="${FIXED[$VERSION]}"
CURRENT=$(php$VERSION -r 'echo PHP_VERSION;' 2>/dev/null || echo "unknown")
echo "Current: $CURRENT"
echo "Required: $REQUIRED"
# Already patched?
if [ "$CURRENT" != "unknown" ] && \
dpkg --compare-versions "$CURRENT" ge "$REQUIRED"; then
echo "PHP $VERSION is already patched."
echo
continue
fi
CANDIDATE=$(apt-cache policy php$VERSION-fpm \
| awk '/Candidate:/ {print $2}')
echo "Package candidate: $CANDIDATE"
if [ "$CANDIDATE" = "(none)" ] || [ -z "$CANDIDATE" ]; then
echo "WARNING: No package candidate available."
echo
continue
fi
# Debian package versions contain additional metadata.
# Example:
# 8.4.27-1+ubuntu24.04.1+deb.sury.org+1
CANDIDATE_PHP=$(echo "$CANDIDATE" \
| sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
echo "Candidate PHP version: $CANDIDATE_PHP"
if ! dpkg --compare-versions "$CANDIDATE_PHP" ge "$REQUIRED"; then
echo "WARNING: Patched PHP $REQUIRED is not available yet."
echo "Skipping PHP $VERSION."
echo
continue
fi
echo
echo "Upgrading PHP $VERSION..."
PACKAGES=$(dpkg -l "php$VERSION*" \
| awk '/^ii/ {print $2}')
if [ -z "$PACKAGES" ]; then
echo "No installed packages found."
echo
continue
fi
apt-get install --only-upgrade -y \
-o Dpkg::Options::="--force-confold" \
$PACKAGES
echo
echo "Verifying PHP $VERSION..."
NEW_VERSION=$(php$VERSION -r 'echo PHP_VERSION;' 2>/dev/null || echo "unknown")
echo "Installed: $NEW_VERSION"
echo "Required: $REQUIRED"
if [ "$NEW_VERSION" != "unknown" ] && \
dpkg --compare-versions "$NEW_VERSION" ge "$REQUIRED"; then
echo "PHP $VERSION successfully patched."
else
echo "ERROR: PHP $VERSION does not appear to be patched."
exit 1
fi
if command -v php-fpm$VERSION >/dev/null 2>&1; then
echo
echo "PHP-FPM:"
php-fpm$VERSION -v | head -1
fi
echo
done
echo "========================================"
echo " PHP security update complete"
echo "========================================"
echo
echo "IMPORTANT:"
echo "Restart any long-running PHP processes:"
echo "- Laravel queue workers"
echo "- Horizon"
echo "- Octane"
echo "- Reverb"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment