Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing PHP Pthreads on Debian 8 Jessie with Apache 2.4

Installing PHP Pthreads on Debian 8 Jessie with Apache 2.4

What we're going to be doing

  • Replacing the installed PHP with a custom compiled version with ZTS enabled (Pthreads requires it).
  • Adding the Pthreads extension through PECL.

Method

  1. Remove existing PHP installations. You should note down here what packages are being removed.

    sudo apt-get remove php5-common

    You may have to mark apache2 as manually installed so it does not get listed under packages to autoremove if you installed php5-common without explicitly installing apache2 first.

    sudo apt-mark manual apache2
  2. Download the PHP build dependencies.

    sudo apt-get build-dep php5

    You may wish to note down the packages installed here if you intend to uninstall them later. Do note that quite a lot of packages will be installed.

  3. Create a directory to store the source files. This is useful as cleaning up will be as simple as removing the directory. It can get a bit messy with all the .deb files we'll be creating.

    mkdir php-dev
    cd php-dev
  4. Download the source files. Do not use sudo here.

    apt-get source php5
  5. Go into the php5 source directory. Use ls to find the exact name of the directory.

    cd php5-5.6.30+dfsg
  6. Open debian/rules in your favourite editor.

    nano debian/rules
  7. Find the COMMON_CONFIG variable and add a new line under it with:

    		--enable-maintainer-zts \
  8. Increment the package version number.

    dch -i

    Edit the top entry of the changelog if you wish but make sure you save either way.

  9. Build PHP.

    DEB_BUILD_OPTIONS=nocheck debuild -us -uc -b --no-lintian

    Do note that this can take quite some time. Go have a break while it's building.

  10. Go back a directory and you should find some .deb files. Install what packages you had before, starting with php5-common. You can find the exact filename through ls.

    cd ..
    sudo dpkg -i php5-common_5.6.30+dfsg-0+deb8u1.1_amd64.deb

    Because some packages depend on others, you may need to do some trial and error to get the right order.

    Do not forget about libapache2-mod-php5! That is built with the PHP source too!

    There's also the core php5 package: php5_5.6.30+dfsg-0+deb8u1.1_all.deb

    php5-dev is also required for later for installing Pthreads.

    sudo dpkg -i php5-dev_5.6.30+dfsg-0+deb8u1.1_amd64.deb
  11. If you need to install any packages that are not a part of the standard PHP source (such as php5-json) then you will need to build them separately. Again, you may have to install some other PHP modules first depending on its dependencies. You will probably be notified during the build if you are unaware.

    Start by downloading the build dependencies of the package you are wanting to build.

    sudo apt-get build-dep php5-json
  12. Then download the source files.

    apt-get source php5-json
  13. Go into the source directory and build.

    cd php-json-1.3.6
    DEB_BUILD_OPTIONS=nocheck debuild -us -uc -b --no-lintian
  14. Increment the package version number.

    dch -i

    Again, make sure to save.

  15. Go back a directory and install.

    cd ..
    sudo dpkg -i php5-json_1.3.6-1.1_amd64.deb
  16. Ensure php-pear is installed if you haven't done so already. It is one of the .deb files that you built.

    sudo dpkg -i php-pear_5.6.30+dfsg-0+deb8u1.1_all.deb
  17. Install Pthreads through PECL

    sudo pecl install pthreads

    If you get the following error:

    shtool at '/tmp/pear/temp/pthreads/build/shtool' does not exist or is not executable.
    Make sure that the file exists and is executable and then rerun this script.
    

    then you need to remount /tmp with the exec flag.

    sudo mount -o remount,exec /tmp/

    You may want to set it back to noexec when you are done installing Pthreads.

    sudo mount -o remount,noexec /tmp/
  18. Create a file at /etc/php5/mods-available/pthread.ini with the following contents

    ; configuration for php pthreads module
    ; priority=20
    extension=pthreads.so
  19. Enable the Pthreads module.

    sudo php5enmod pthreads
  20. Restart apache2.

    sudo /etc/init.d/apache2 restart
  21. Cleanup by removing the directory we created:

    cd ..
    rm -r php-dev

Well done, you did it!

Updating PHP

Updates to PHP will show in apt-get, and upgrading will replace your changes! There's a few ways to combat this, including changing the epoch version and "holding" the repository via dpkg. I check dist-upgrade before going ahead, so I don't bother with this and the presence of php* in fact reminds me to upgrade, but everyone's setup is different. See http://serverfault.com/questions/83727/apt-get-conflict-after-installing-a-local-deb/83744 for ideas.

As for performing the updating of PHP, then you will unfortunately need to repeat the process (minus the configuration stages). It works best to delete (step 16) and download the source files each time so that you get fresh config/version files instead of modified ones from your last build. You will have a much happier relationship with debuild if you do it this way. Maybe someday ZTS support will be in the Debian package repositories.

@VitaliyKuznetsov

This comment has been minimized.

Copy link

@VitaliyKuznetsov VitaliyKuznetsov commented May 4, 2016

Hello, i found a error in your insctruction.
It presented on screen:
image

@Bo98

This comment has been minimized.

Copy link
Owner Author

@Bo98 Bo98 commented Jan 13, 2017

Thanks @VitaliyKuznetsov. Apparently I don't get notifications for Gist comments, so I only noticed your comment now - 8 months later! Sorry about that!

@lbalmont

This comment has been minimized.

Copy link

@lbalmont lbalmont commented Mar 11, 2019

Hello, I add just a thing :
do a
pecl install pthreads-2.0.10 instead pecl install pthreads
because in the default channel, PECL try to install v3 for php7 and I had error :

# sudo pecl install pthreads
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
pecl/pthreads requires PHP (version >= 7.0.0RC5), installed version is 5.6.40-0+deb8u1.1
No valid packages found
install failed

Elseif, many thanks for this turorial ! And sorry for my FrEnglish.

@lbalmont

This comment has been minimized.

Copy link

@lbalmont lbalmont commented Mar 11, 2019

Another tip :
If you have error with --no-lintian option, like :

# DEB_BUILD_OPTIONS=nocheck debuild -us -uc -b --no-lintian 
debuild: unknown dpkg-buildpackage/debuild option: --no-lintian
 dpkg-buildpackage -rfakeroot -D -us -uc -b --no-lintian
dpkg-buildpackage: option ou paramètre inconnu --no-lintian

Use --help for program usage information.
debuild: fatal error at line 1376:
dpkg-buildpackage -rfakeroot -D -us -uc -b --no-lintian failed

You must use --no-lintian @ first :
# DEB_BUILD_OPTIONS=nocheck debuild --no-lintian -us -uc -b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment