You want to use PCRE2 compiled from source (tarball) on Debian 12 with PHP 8.2. This usually means you want PHP to use your custom-built PCRE2 library instead of the system one.
Here’s a step-by-step guide to do that:
1. Compile and install PCRE2 from tarball
Let's assume you downloaded PCRE2 source (e.g., pcre2-10.x.tar.gz).
cd /usr/local/src
wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.gz
tar xvf pcre2-10.40.tar.gz
cd pcre2-10.40
# Configure and install PCRE2.
# Let's install it under /usr/local/pcre2 to avoid conflict with system libs.
./configure --prefix=/usr/local/pcre2 --enable-jit
make
sudo make install
This installs PCRE2 header files and libs under /usr/local/pcre2.
2. Configure PHP 8.2 source or extension build to use your PCRE2
Option A: If you are compiling PHP from source
You need to tell PHP's configure script where PCRE2 is located.
# Assuming you have PHP 8.2 source
cd /path/to/php-8.2-source
./configure \
--with-pcre-regex=/usr/local/pcre2 \
...other options...
make
sudo make install
Note:
The --with-pcre-regex option tells PHP where to find PCRE2 headers/libs. Replace /usr/local/pcre2 with your PCRE2 install prefix.
Option B: Using PHP’s PCRE extension (if built separately)
If you want to build or use the pcre extension separately (usually PCRE is built-in now), make sure when you compile the extension, your compiler and linker use your installed PCRE2:
export PKG_CONFIG_PATH=/usr/local/pcre2/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/usr/local/pcre2/lib:$LD_LIBRARY_PATH
# Example building PHP extension
phpize
./configure --with-pcre-regex=/usr/local/pcre2
make
sudo make install
3. Make sure runtime linker finds your PCRE2 libs
Add /usr/local/pcre2/lib to /etc/ld.so.conf.d/pcre2.conf:
echo "/usr/local/pcre2/lib" | sudo tee /etc/ld.so.conf.d/pcre2.conf
sudo ldconfig
This ensures the dynamic linker finds your libpcre2-8.so, etc.
4. Verify PHP uses PCRE2 from your path
After installing PHP or the extension, check that PHP uses your PCRE2 version.
php -i | grep -i pcre
You should see info about PCRE2’s version, and it usually reports runtime PCRE version.
Alternatively, you can run:
<?php
var_dump(pcre_version());
?>
If you see the PCRE2 version you compiled, it means PHP is using your PCRE2 library.
Summary
- Compile and install PCRE2 from source into a custom prefix (e.g.,
/usr/local/pcre2)
- Configure PHP build (
./configure) to use that PCRE2 directory via --with-pcre-regex=...
- Make sure runtime linker can find the custom PCRE2 libs (
ldconfig step)
- Rebuild and reinstall PHP or PCRE extension
- Verify PHP uses your custom PCRE2 at runtime
Notes
- Debian 12 ships a PCRE2 version in the system repos, and PHP 8.2 installed via the official Debian packages usually links to that system version.
- If you just want to update PCRE2 system-wide, consider using Debian packages or backporting instead of manual build.
- Building PHP from source is required to link against a custom PCRE2; otherwise, your PHP install will not see your custom PCRE2 version.
- Carefully check
/usr/local/pcre2/lib is prioritized at runtime to avoid the system default libs.
If you want, I can provide exact commands for your use case or help with compiling PHP 8.2 yourself.