From 5f3c3c9793dff50e32b5b07d3fd8295b02925cae Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 20 Nov 2026 06:00:02 +0530 Subject: [PATCH 1/5] fix(migration): pin existing latest-PHP sites to the version they run Sites created with --php=latest store `latest` and run the image `latest` mapped to when their docker-compose.yml was last generated (php8.4 since 4.13.x), with a php config made for that version. Now that `latest` maps to 8.5, their next compose regeneration (ee site refresh, or an upgrade that bumps one of their images) would move them to the php8.5 image with the 8.4 conf.d, and every php/php-fpm start would warn about opcache, gmagick and newrelic. Like the 7.4 migration before it, rewrite each `latest` row to a concrete version: the one in the site's docker-compose.yml (the unversioned easyengine/php image is 7.4), or 8.4 when the file is missing or names no single known version. Only the DB rows change; no file or container is touched. --- ...00_site-command_pin_latest_php_version.php | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 migrations/db/20261120120000_site-command_pin_latest_php_version.php diff --git a/migrations/db/20261120120000_site-command_pin_latest_php_version.php b/migrations/db/20261120120000_site-command_pin_latest_php_version.php new file mode 100644 index 00000000..59293f3d --- /dev/null +++ b/migrations/db/20261120120000_site-command_pin_latest_php_version.php @@ -0,0 +1,109 @@ + image. */ + const KNOWN_VERSIONS = [ '5.6', '7.0', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6' ]; + + /** The unversioned easyengine/php image, `latest` before 2024, is PHP 7.4. */ + const UNVERSIONED_IMAGE_VERSION = '7.4'; + + /** Largest docker-compose.yml read. */ + const MAX_SIZE = 1048576; + + private $sites; + + public function __construct() { + + parent::__construct(); + $this->sites = Site::all(); + if ( $this->is_first_execution || ! $this->sites ) { + $this->skip_this_migration = true; + } + } + + /** + * Rewrite every `latest` php_version to the version in the site's docker-compose.yml. + * + * @throws EE\ExitException + */ + public function up() { + + if ( $this->skip_this_migration ) { + EE::debug( 'Skipping pin-latest-php-version migration as it is not needed.' ); + + return; + } + foreach ( $this->sites as $site ) { + + if ( 'latest' !== $site->php_version ) { + continue; + } + $version = $this->running_version( $site ); + if ( null === $version ) { + $version = self::FALLBACK_VERSION; + EE::debug( "Could not read the PHP image of $site->site_url from its docker-compose.yml; using PHP $version." ); + } + $site->php_version = $version; + $site->save(); + EE::log( "Set the PHP version of $site->site_url from latest to $version, the version it runs." ); + } + } + + /** + * The PHP version of the php image in the site's docker-compose.yml. + * + * @param Site $site + * + * @return string|null Null when the file is missing or unreadable, or names no single known version. + */ + private function running_version( $site ) { + + if ( empty( $site->site_fs_path ) ) { + return null; + } + $file = rtrim( $site->site_fs_path, '/' ) . '/docker-compose.yml'; + if ( ! is_file( $file ) || ! is_readable( $file ) ) { + return null; + } + $content = @file_get_contents( $file, false, null, 0, self::MAX_SIZE ); + if ( false === $content || ! preg_match_all( '#^\s*image:\s*["\']?easyengine/php(\d+\.\d+)?:#m', $content, $matches ) ) { + return null; + } + $versions = array_unique( + array_map( + function ( $version ) { + return '' === $version ? self::UNVERSIONED_IMAGE_VERSION : $version; + }, + $matches[1] + ) + ); + if ( 1 !== count( $versions ) ) { + return null; + } + $version = reset( $versions ); + + return in_array( $version, self::KNOWN_VERSIONS, true ) ? $version : null; + } + + /** + * No changes in case of down. + * + * @throws EE\ExitException + */ + public function down() { + } +} From 81a9c4d4776bccd36fabc3a7c3fa34ab9812a92b Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 20 Nov 2026 06:04:34 +0530 Subject: [PATCH 2/5] fix(migration): fail on an unsaved PHP version pin and read untagged php images A row that can't be saved now fails the migration with the site's name instead of being logged as pinned; the migration then runs again on the next command and skips the rows already pinned. The php image is also read when the compose file names it without a tag or by digest. --- ...20000_site-command_pin_latest_php_version.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/migrations/db/20261120120000_site-command_pin_latest_php_version.php b/migrations/db/20261120120000_site-command_pin_latest_php_version.php index 59293f3d..35f5a9c7 100644 --- a/migrations/db/20261120120000_site-command_pin_latest_php_version.php +++ b/migrations/db/20261120120000_site-command_pin_latest_php_version.php @@ -38,7 +38,7 @@ public function __construct() { /** * Rewrite every `latest` php_version to the version in the site's docker-compose.yml. * - * @throws EE\ExitException + * @throws \Exception When a row can't be saved. */ public function up() { @@ -58,7 +58,17 @@ public function up() { EE::debug( "Could not read the PHP image of $site->site_url from its docker-compose.yml; using PHP $version." ); } $site->php_version = $version; - $site->save(); + $error = ''; + try { + $saved = $site->save(); + } catch ( \Throwable $e ) { + $saved = false; + $error = ': ' . $e->getMessage(); + } + // Fail so the migration isn't recorded and runs again; rows already pinned are skipped then. + if ( ! $saved ) { + throw new \Exception( "Could not set the PHP version of $site->site_url to $version$error" ); + } EE::log( "Set the PHP version of $site->site_url from latest to $version, the version it runs." ); } } @@ -80,7 +90,7 @@ private function running_version( $site ) { return null; } $content = @file_get_contents( $file, false, null, 0, self::MAX_SIZE ); - if ( false === $content || ! preg_match_all( '#^\s*image:\s*["\']?easyengine/php(\d+\.\d+)?:#m', $content, $matches ) ) { + if ( false === $content || ! preg_match_all( '#^\s*image:\s*["\']?easyengine/php(\d+\.\d+)?(?=[:@"\'\s]|$)#m', $content, $matches ) ) { return null; } $versions = array_unique( From a15a6bb28c9a7c0d6a4c6565952db388b2cd41c4 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 20 Nov 2026 06:08:45 +0530 Subject: [PATCH 3/5] fix(migration): fall back to PHP 8.4 when a site uses a custom php image Every easyengine/php image in the compose file is now checked, so a custom one (e.g. php8.3-custom) next to a plain one no longer pins the site to the plain one's version. --- ...00_site-command_pin_latest_php_version.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/migrations/db/20261120120000_site-command_pin_latest_php_version.php b/migrations/db/20261120120000_site-command_pin_latest_php_version.php index 35f5a9c7..7a87817c 100644 --- a/migrations/db/20261120120000_site-command_pin_latest_php_version.php +++ b/migrations/db/20261120120000_site-command_pin_latest_php_version.php @@ -90,17 +90,22 @@ private function running_version( $site ) { return null; } $content = @file_get_contents( $file, false, null, 0, self::MAX_SIZE ); - if ( false === $content || ! preg_match_all( '#^\s*image:\s*["\']?easyengine/php(\d+\.\d+)?(?=[:@"\'\s]|$)#m', $content, $matches ) ) { + // The image name after "easyengine/php", up to its tag or digest. + if ( false === $content || ! preg_match_all( '#^\s*image:\s*["\']?easyengine/php([^\s"\'@:]*)#m', $content, $matches ) ) { return null; } - $versions = array_unique( - array_map( - function ( $version ) { - return '' === $version ? self::UNVERSIONED_IMAGE_VERSION : $version; - }, - $matches[1] - ) - ); + $versions = []; + foreach ( $matches[1] as $suffix ) { + if ( '' === $suffix ) { + $versions[] = self::UNVERSIONED_IMAGE_VERSION; + } elseif ( preg_match( '#^\d+\.\d+$#D', $suffix ) ) { + $versions[] = $suffix; + } else { + // Another image (e.g. php8.3-custom): the site isn't on a plain EasyEngine php image. + return null; + } + } + $versions = array_unique( $versions ); if ( 1 !== count( $versions ) ) { return null; } From 6b2b9612f59dbfaf596c6ca3e46563b768302941 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 20 Nov 2026 06:13:13 +0530 Subject: [PATCH 4/5] fix(migration): read the php image from the services of the parsed compose file Only the image field of each service counts, so image-like text elsewhere (an environment value, a label) is ignored. The file is parsed with Spyc, which the phar ships; symfony/yaml is stripped from it. --- ...00_site-command_pin_latest_php_version.php | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/migrations/db/20261120120000_site-command_pin_latest_php_version.php b/migrations/db/20261120120000_site-command_pin_latest_php_version.php index 7a87817c..bd59d210 100644 --- a/migrations/db/20261120120000_site-command_pin_latest_php_version.php +++ b/migrations/db/20261120120000_site-command_pin_latest_php_version.php @@ -4,6 +4,7 @@ use EE; use EE\Model\Site; +use Mustangostang\Spyc; /** * Pins sites stored as `latest` to the PHP version they run. @@ -90,16 +91,28 @@ private function running_version( $site ) { return null; } $content = @file_get_contents( $file, false, null, 0, self::MAX_SIZE ); - // The image name after "easyengine/php", up to its tag or digest. - if ( false === $content || ! preg_match_all( '#^\s*image:\s*["\']?easyengine/php([^\s"\'@:]*)#m', $content, $matches ) ) { + try { + // Spyc, as symfony/yaml isn't in the phar. + $compose = false === $content ? null : Spyc::YAMLLoadString( $content ); + } catch ( \Exception $e ) { + return null; + } + if ( ! is_array( $compose ) || ! isset( $compose['services'] ) || ! is_array( $compose['services'] ) ) { return null; } $versions = []; - foreach ( $matches[1] as $suffix ) { - if ( '' === $suffix ) { + foreach ( $compose['services'] as $service ) { + if ( ! is_array( $service ) || ! isset( $service['image'] ) || ! is_string( $service['image'] ) ) { + continue; + } + // The image name after "easyengine/php", up to its tag or digest. + if ( ! preg_match( '#^easyengine/php([^@:]*)#', $service['image'], $match ) ) { + continue; + } + if ( '' === $match[1] ) { $versions[] = self::UNVERSIONED_IMAGE_VERSION; - } elseif ( preg_match( '#^\d+\.\d+$#D', $suffix ) ) { - $versions[] = $suffix; + } elseif ( preg_match( '#^\d+\.\d+$#D', $match[1] ) ) { + $versions[] = $match[1]; } else { // Another image (e.g. php8.3-custom): the site isn't on a plain EasyEngine php image. return null; From 17128fd91db62441a0937674aff3932b7eac2f2d Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 20 Nov 2026 06:22:30 +0530 Subject: [PATCH 5/5] fix(migration): fall back to PHP 8.4 when Spyc can't parse a compose file Spyc throws a TypeError on PHP 8 for some malformed YAML (a scalar merge key), which stopped the migration on every run. A missing Spyc still fails loudly instead of looking like an unreadable file. --- ...61120120000_site-command_pin_latest_php_version.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/migrations/db/20261120120000_site-command_pin_latest_php_version.php b/migrations/db/20261120120000_site-command_pin_latest_php_version.php index bd59d210..c9bfbb5e 100644 --- a/migrations/db/20261120120000_site-command_pin_latest_php_version.php +++ b/migrations/db/20261120120000_site-command_pin_latest_php_version.php @@ -90,11 +90,15 @@ private function running_version( $site ) { if ( ! is_file( $file ) || ! is_readable( $file ) ) { return null; } + // Spyc, as symfony/yaml isn't in the phar. Its absence must fail loudly, not look like an unreadable file. + if ( ! class_exists( Spyc::class ) ) { + throw new \Exception( 'Spyc is not available to read docker-compose.yml files.' ); + } $content = @file_get_contents( $file, false, null, 0, self::MAX_SIZE ); try { - // Spyc, as symfony/yaml isn't in the phar. - $compose = false === $content ? null : Spyc::YAMLLoadString( $content ); - } catch ( \Exception $e ) { + // Malformed YAML can make Spyc throw a TypeError on PHP 8. + $compose = false === $content ? null : @Spyc::YAMLLoadString( $content ); + } catch ( \Throwable $e ) { return null; } if ( ! is_array( $compose ) || ! isset( $compose['services'] ) || ! is_array( $compose['services'] ) ) {