Here's an updated guide for compiling PHP 8.3 with ZTS support, which is required for pthreads or parallel extensions:
sudo apt-get update
sudo apt-get install -y build-essential autoconf bison re2c \
libxml2-dev libsqlite3-dev libssl-dev zlib1g-dev \
libcurl4-openssl-dev libonig-dev libreadline-dev \
libzip-dev pkg-config git
wget https://www.php.net/distributions/php-8.3.0.tar.gz
tar -xzvf php-8.3.0.tar.gz
cd php-8.3.0
./buildconf --force
./configure \
--prefix=/usr/local/php8.3-zts \
--enable-zts \
--enable-mbstring \
--enable-intl \
--enable-pcntl \
--enable-phpdbg \
--enable-opcache \
--with-openssl \
--with-pear \
--with-readline \
--with-zlib \
--with-curl \
--enable-cli
make -j$(nproc)
sudo make install
/usr/local/php8.3-zts/bin/php -i | grep "Thread Safety"
This should output: Thread Safety => enabled
For modern PHP threading, you'll want the parallel extension:
git clone https://github.com/krakjoe/parallel.git
cd parallel
/usr/local/php8.3-zts/bin/phpize
./configure --with-php-config=/usr/local/php8.3-zts/bin/php-config
make
sudo make install
Add the extension to your php.ini:
extension=parallel.so
- PHP 8.3's ZTS implementation has improved thread safety features compared to older versions.
- The parallel extension is the modern alternative to pthreads for PHP 8.x.
- Remember that not all PHP extensions are thread-safe, even with ZTS enabled.
- For production use, consider additional configuration options based on your needs.
To use this PHP installation as your default, add it to your PATH:
export PATH="/usr/local/php8.3-zts/bin:$PATH"