Skip to content

Build PHP binaries with Xdebug - #3439

Merged
fredrikekelund merged 35 commits into
trunkfrom
rsm-2698-build-php-with-xdebug
May 19, 2026
Merged

Build PHP binaries with Xdebug#3439
fredrikekelund merged 35 commits into
trunkfrom
rsm-2698-build-php-with-xdebug

Conversation

@fredrikekelund

@fredrikekelund fredrikekelund commented May 12, 2026

Copy link
Copy Markdown
Contributor

Related issues

  • Related to RSM-2698

How AI was used in this PR

Codex and Claude were both used heavily to iterate on the build script, even if we ultimately arrived at a relatively simple change compared to trunk.

Proposed Changes

We use crazywhalecc/static-php-cli to build PHP binaries. The big selling point of that project is that it can bundle PHP extensions into the binary itself (normally they're distributed as separate .so/.dll files, so called "shared" extensions). It turns out that Xdebug cannot be compiled into the static PHP binary (docs). AFAICT, this is an inherent limitation in Xdebug.

However, static-php-cli can actually handle shared extensions, too. Adding support for Xdebug specifically seems to have been a key motivation behind implementing this. The only blocker is that this only works on Posix systems, not on Windows.

So, to get Xdebug support on both platforms, this PR does the following:

  1. Continue using static-php-cli to build the macOS PHP binary. Xdebug is built as a shared extension that ends up in ext/xdebug.so
  2. On Windows, use the official php.net build and repackage it so that extensions are stored in the ext directory.
  3. Add a runtime.json file for both platforms that serves as a reference for the build version, where the binary lives, and where the extension directory is. I'm not sure how useful this will be in practice, but it seems like a decent idea.

Testing Instructions

I'll run the GitHub Actions workflow for all supported PHP versions and manually confirm the output.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@fredrikekelund
fredrikekelund requested a review from bcotrim May 12, 2026 07:12
@fredrikekelund fredrikekelund self-assigned this May 12, 2026
artifact_arch: aarch64
binary_name: php
extensions: &macos_php_extensions apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gettext,iconv,igbinary,imagick,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,shmop,simplexml,sockets,sodium,sqlite3,ssh2,tokenizer,xml,xmlreader,xmlwriter,xsl,yaml,zip,zlib
extensions: &macos_extensions apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gettext,iconv,igbinary,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,shmop,simplexml,sockets,sodium,sqlite3,ssh2,tokenizer,xdebug,xml,xmlreader,xmlwriter,xsl,yaml,zip,zlib

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed imagick. I'd love to keep it in, but it's not included in the official php.net Windows build, so I skipped it for now.

@fredrikekelund
fredrikekelund marked this pull request as ready for review May 13, 2026 14:20
@fredrikekelund
fredrikekelund merged commit a9470c7 into trunk May 19, 2026
10 checks passed
@fredrikekelund
fredrikekelund deleted the rsm-2698-build-php-with-xdebug branch May 19, 2026 05:35
fredrikekelund added a commit that referenced this pull request May 19, 2026
## Related issues

<!--
Link a related issue to this PR. If the PR does not immediately resolve
the issue,
for example, it requires a separate deployment to production, avoid
using the "Fixes" keyword and use "Related to" instead.
-->

- Follow up to #3439
- Fixes RSM-2698

## How AI was used in this PR

<!--
Help reviewers understand what to look for and verify that you've
reviewed the code yourself.
-->

Claude drove the entire implementation based on a detailed spec from me.

## Proposed Changes

#3439 changes the structure of
the PHP package for Windows so that the extensions are no longer static
but are distributed as separate DLL files. To account for this, we need
to tell PHP where to find the extension files and to activate them. This
PR does that.

This PR also activates Xdebug when the `enableXdebug` config is true.

## Testing Instructions

<!--
Add as many details as possible to help others reproduce the issue and
test the fix.
"Before / After" screenshots can also be very helpful when the change is
visual.
-->

1. Be on Windows
2. Download the Windows build from
[here](https://github.com/Automattic/studio/actions/runs/25800854923)
3. Extract it to `C:\Users\USERNAME\.studio\php-bin\8.4` (replace the
existing content)
4. `npx cross-env STUDIO_RUNTIME=native-php npm start`
5. Create a new site with PHP 8.4
6. Ensure that it starts as expected
7. Activate Xdebug in the site settings
8. Ensure that it works (you can add a `phpinfo.php` file in the site
root and put a `phpinfo()` call in there for verification)

## Pre-merge Checklist

<!--
Complete applicable items on this checklist **before** merging into
trunk. Inapplicable items can be left unchecked.

Both the PR author and reviewer are responsible for ensuring the
checklist is completed.
-->

- [ ] Have you checked for TypeScript, React or other console errors?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant