If you find this add-on useful, please star it on GitHub — stars show appreciation and help maintainers know their work matters.
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:
ddev xdebug doesn’t work. xhprof isn’t built by default, and ddev xhprof hasn’t been tested with it. See extension support.ddev start, and it takes a long time on the first ddev start or 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.ddev utility rebuild or DDEV_VERBOSE=true ddev start.php_version setting doesn’t choose the PHP binary, but DDEV’s php.ini and php-fpm configuration still come from it. Set php_version to the same minor version you build, for example ddev config --php-version=8.5 for 8.5.12. See PHP configuration.ddev utility rebuild -s web --cachephp-fpm) which can be used to replace the ones installed in ddev-webserver..ddev/web-build/Dockerfile.php-patch-build does the building.# Set your desired PHP version, when prompted, e.g., 8.4.10
ddev add-on get rfay/ddev-php-patch-build
ddev restart
After 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 restart
Run 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 restart
Only 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 restart
After 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_token
DDEV 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
If you find this add-on useful, please star it on GitHub — stars show appreciation and help maintainers know their work matters.