Thanks for that info! You're right — in PHP 8.2, the --with-pcre-regex option does not exist (hence the "unrecognized options" warning).
PHP 8.2 uses bundled PCRE2 by default and does not provide a configure option to use an external/custom PCRE2 installation. Unfortunately, it always builds with the bundled PCRE2 and does not officially support swapping in a custom PCRE2 library like you could in older PHP versions.
How to make PHP 8.2.29 use your custom-compiled PCRE2?
Option 1: Patch the PHP source (advanced and quite involved)
You would need to modify the PHP source build system to:
- Disable building bundled PCRE2
- Link against your external PCRE2
This is not straightforward since the build system always compiles bundled PCRE2 sources.
Option 2: Replace bundled PCRE2 sources with your PCRE2 sources (experimental)
You could:
- Remove or move away the bundled PCRE2 source code inside the PHP source tree
- Adjust build scripts/config files to point/include your PCRE2
- This is very hacky and fragile, not recommended unless you know the internals well.
Option 3: Use bundled PCRE2 but build it with your custom flags (preferred workaround)
When you want something special like --enable-jit or specific compiler options, you can:
- Patch or modify the bundled PCRE2 build inside the PHP source tree (
ext/pcre2)
- Edit
ext/pcre2/config.m4 or makefile to add extra compiler flags or enable options like JIT
- Then build PHP as usual
Example:
-
Go to php-8.2.29/ext/pcre2
-
Edit the build files (such as config.m4) to add flags:
PHP_ADD_BUILD_FLAGS("-DENABLE_JIT=1")
-
Alternatively, modify the Makefile or compiler flags to enable JIT or whatever you want.
-
Rebuild PHP.
Summary:
| Action | Supported in PHP 8.2? | Notes |
|---|
Use --with-pcre-regex configure option | No | Unsupported, causes a warning |
| Use system PCRE2 instead of bundled | No | PHP uses only bundled PCRE2 in 8.2 |
| Patch PHP source to use external PCRE2 | Possible but complex | Requires manual source code and build system changes |
| Customize bundled PCRE2 build inside PHP | Yes, recommended workaround | Patch bundled PCRE2 build configs or flags |
More Concrete Steps if you want to customize bundled PCRE2 in PHP 8.2.29
- Inside PHP source, edit
ext/pcre2/config.m4 to add flags:
Search for build flags or PHP_ADD_BUILD_FLAG.
Add your own flags, for example:
PHP_ADD_BUILD_FLAGS("-DENABLE_JIT")
For example, the official bundled PCRE2 config.h has options to enable JIT.
- Export environment flags when running
configure:
export CFLAGS="-O3 -march=native"
export CXXFLAGS="-O3 -march=native"
./configure [your options]
make -j$(nproc)
sudo make install
- To verify JIT is enabled in PCRE2 (PHP bundled):
You may confirm from phpinfo() or try profiling with a large regex.
If you really want to build PHP with external PCRE2 (outside bundled):
You can try the following complicated approach, but it's not guaranteed and requires patching PHP:
- Disable building bundled PCRE2 by adjusting the
ext/pcre2/ directory or build files
- Pass
--with-pcre-regex=shared,/opt/pcre2 or similar (not officially supported)
- Adjust linking flags (LDFLAGS, CPPFLAGS, PKG_CONFIG_PATH)
References & Links
If you want help patching PHP's build system or tweaking bundled PCRE2 build options, I can assist with that. Just say!