DDEV users periodically ask if they can use a specific PHP patch version with their projects, either to test/compare for a particular bug or to match a production version exactly.
This experimental add-on tries to address that need, although there are a number of caveats:
- The build done using this process uses the technique from static-php-cli and full details are available there. It builds PHP 8.1 and later, including PHP 8.6 pre-releases, see Pre-release versions. static-php-cli doesn't support PHP 7.x, and support for 8.0 and 8.1 is best-effort. The tests cover 8.1, 8.4, 8.5 and 8.6.
- The build does not match the build done using the official DDEV php packages (which actually come from deb.sury.org.
- It does not provide Xdebug, so
ddev xdebugdoesn't work.xhprofisn't built by default, andddev xhprofhasn't been tested with it. See extension support. - The resultant PHP binaries built here do not have the exact same extensions as the official DDEV PHP binaries, see Extensions.
- Building the binaries happens in the build phase of
ddev start, and it takes a long time on the firstddev startor whenever you change versions. The build uses static-php-cli's pre-built libraries where they exist; with the default extensions it took about 9 minutes on an Apple Silicon Mac. Each extension you add makes it longer. - If you want to see the build process as it proceeds, you can use
ddev utility rebuildorDDEV_VERBOSE=true ddev start. - When you use this add-on, your DDEV
php_versionsetting doesn't choose the PHP binary, but DDEV'sphp.iniandphp-fpmconfiguration still come from it. Setphp_versionto the same minor version you build, for exampleddev config --php-version=8.5for 8.5.12. See PHP configuration. - To see what's going on during the build, use
ddev utility rebuild -s web --cache - Your mileage may vary.
- The static-php-cli repository provides a relatively easy way to build static PHP binaries (the CLI and
php-fpm) which can be used to replace the ones installed inddev-webserver. - The provided
.ddev/web-build/Dockerfile.php-patch-builddoes the building.
# Set your desired PHP version, when prompted, e.g., 8.4.10
ddev add-on get rfay/ddev-php-patch-build
ddev restartAfter installation, make sure to commit the .ddev directory to version control.
The static PHP binaries use DDEV's php.ini for the CLI and for php-fpm, so DDEV's settings such as memory_limit, upload limits and Mailpit's sendmail_path apply as usual.
Custom settings in .ddev/php/*.ini work as with the regular DDEV PHP. Don't put extension= lines in them: static PHP can't load shared extensions. Add the extension to STATIC_PHP_EXTENSIONS instead.
Run ddev php --ini to see which files are loaded.
The default build includes the extensions most projects need, listed under STATIC_PHP_EXTENSIONS below.
These extensions in the regular DDEV PHP aren't built by default, but you can add them to STATIC_PHP_EXTENSIONS. Each one adds to the build time:
bz2, ffi, gettext, igbinary, imagick, ldap, memcached, msgpack, readline, redis, shmop, soap, sockets, sysvmsg, sysvsem, sysvshm, xhprof, xsl, yaml
Setting STATIC_PHP_EXTENSIONS replaces the default list, so start from the default and add to it. For example, to add redis and igbinary:
ddev dotenv set .ddev/.env.php-patch-build --static-php-extensions="apcu,bcmath,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,iconv,intl,mbstring,mysqli,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,phar,posix,session,simplexml,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,redis,igbinary"
ddev restartRun ddev php -m to check which extensions are built in. See static-php-cli's extension list for everything it can build.
These are not available:
uploadprogress: not supported by static-php-cli. Applications such as Drupal still work, but don't show upload progress bars.xdebug: see the caveats above.xmlrpc: not supported by static-php-cli.
You can build the current release candidate of a PHP version that isn't released yet, such as 8.6.0RC4:
ddev config --php-version=8.6
ddev dotenv set .ddev/.env.php-patch-build --static-php-version=8.6.0RC4
ddev add-on get rfay/ddev-php-patch-build
ddev restartOnly the current pre-release listed on php.net can be downloaded, so update --static-php-version when a new one comes out.
For PHP 8.6, APCu is built from an unreleased commit because the latest APCu release doesn't support PHP 8.6. If your DDEV version doesn't support php_version: 8.6, use 8.5; it only affects which php.ini is used.
You can choose a different PHP version with:
ddev dotenv set .ddev/.env.php-patch-build --static-php-version=8.4.10
ddev add-on get rfay/ddev-php-patch-build
ddev restartAfter installation, make sure to commit the .ddev directory to version control.
If you hit GitHub rate limits while downloading static-php-cli extensions, export your token before running ddev start to build the PHP binaries:
export DDEV_GITHUB_TOKEN=your_github_tokenDDEV passes DDEV_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN to the build as a secret, so the token isn't stored in the image. This requires DDEV newer than v1.25.4; older versions build without a token.
| Variable | Flag | Default |
|---|---|---|
STATIC_PHP_EXTENSIONS |
--static-php-extensions |
apcu,bcmath,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,iconv,intl,mbstring,mysqli,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,phar,posix,session,simplexml,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip (opcache is added for PHP 8 and later) |
STATIC_PHP_VERSION |
--static-php-version |
required, (not set) |
Contributed and maintained by @rfay