I have been strugling for hours on how to install pthread in my ubuntu server to allow php threading. Please help me.
-
Related: [How to install PHP pthreads extension on Ubuntu](http://stackoverflow.com/q/15782860) – mario Aug 03 '13 at 13:23
1 Answers
HOW TO INSTALL IN LINUX SYSTEM'S:
The following instructions will result in an isolated installation of PHP that does not affect your current installation.
1) Checkout PHP sources into a new directory on your system
cd /usr/src
git clone https://github.com/php/php-src
cd php-src
1a) Optionally checkout a specific version of PHP
git checkout PHP-5.6
2) Download the pthreads sources to the build directory (/ext)
cd ext
git clone https://github.com/krakjoe/pthreads
cd ../
3) Configure new isolated PHP installation
./buildconf --force
./configure --prefix=/opt/php-zts \
--bindir=/opt/php-zts/bin \
--with-config-file-dir=/opt/php-zts \
--with-config-file-scan-dir=/opt/php-zts/modules.d/ \
--enable-pthreads=shared \
--with-curl=shared,/usr \
--with-zlib \
--with-libxml2 \
--enable-simplexml \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-gd-native-ttf \
--with-mysqli \
--enable-shared \
--enable-maintainer-zts \
--enable-sockets \
--with-curl=shared \
--enable-mbstring
make -j8
make install
echo "extension=pthreads.so" > /opt/php-zts/modules.d/pthreads.ini
The configure command used here will result in a fairly standard installation with a sensible set of modules. If the build process fails, you should be able to resolve errors by installing developement packages, for example should the curl module fail to configure or build then
yum install curl-devel
Or the equivalent for your system should resolve the error, allowing the build to continue.
4) Symlink some useful things in /opt/php-zts/bin to /usr/local/bin
ln -s /opt/php-zts/bin/php /usr/local/bin/php-zts
ln -s /opt/php-zts/bin/phpize /usr/local/bin/phpize-zts
ln -s /opt/php-zts/bin/php-config /usr/local/bin/php-config-zts
ln -s /opt/php-zts/bin/php-cgi /usr/local/bin/php-cgi-zts
ln -s /opt/php-zts/bin/phpdbg /usr/local/bin/phpdbg-zts
At this point you have a working installation of PHP (version of your chosen branch or master if none) with pthreads available.
BUILDING MODULES FOR USE WITH ISOLATED INSTALLATION:
The procedure for building modules is as follows (APCu used for example):
cd /usr/src
git clone https://github.com/krakjoe/acpu
cd apcu
phpize-zts
./configure --with-php-config=php-config-zts
make -j8
make install
echo "extension=apcu.so" > /opt/php-zts/modules.d/apcu.ini
You must be sure to pass the correct php-config path when building modules since by default your system installation of PHP will be detected.
All blockquoted commands are ok for copypasta.

- 17,032
- 5
- 41
- 62

- 358
- 2
- 9
-
1i followed this tutorial before, but it gives me an error on the second command 'No releases available for package "pecl.php.net/pthread" install failed' – Arh Hokagi Aug 03 '13 at 13:58
-
I have the same problem ... I notice that this is the same installation way as on http://www.php.net/manual/en/pthreads.installation.php but it not works! – Catalin Cardei Oct 13 '13 at 11:18
-
Joe's [latest (excellent) work](http://stackoverflow.com/questions/23019636/how-to-install-pthreads-on-a-phpfarm-php-installation#answer-23020481) intended to solve this scenario – Ricalsin Apr 15 '14 at 19:09
-
1This tutorial is really helpful, but I followed all of the steps and received no errors, but I am still running my old version of PHP, I am not sure how to activate the new version. Is there something I have to do to activate the new version of PHP? – Kevin Weber May 13 '15 at 13:36
-