Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save VitaliyKuznetsov/63d8d9fe85b610c307059d9918626512 to your computer and use it in GitHub Desktop.
Save VitaliyKuznetsov/63d8d9fe85b610c307059d9918626512 to your computer and use it in GitHub Desktop.
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. Download the source files. Do not use sudo here.

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

    cd php5-5.6.9+dfsg
  5. Open debian/rules in your favourite editor.

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

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

    dch -i

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

  8. Build PHP.

    DEB_BUILD_OPTIONS=nocheck debuild -us -uc

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

  9. 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.9+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!

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

    sudo dpkg -i php5-dev_5.6.9+dfsg-0+deb8u1.1_amd64.deb
  10. 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
  11. Then download the source files.

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

    cd php-json-1.3.6
    DEB_BUILD_OPTIONS=nocheck debuild -us -uc
  13. Increment the package version number.

    dch -i

    Again, make sure to save.

  14. Go back a directory and install.

    cd ..
    sudo dpkg -i php5-json_1.3.6-1.1_amd64.deb
  15. 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.9+dfsg-0+deb8u1.1_all.deb
  16. 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/
  17. Create a file at /etc/php5/mods-available/pthread.ini with the following contents

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

    sudo php5enmod pthreads
  19. Restart apache2.

    sudo /etc/init.d/apache2 restart
  20. Cleanup by removing any source directories and .deb files.

Well done, you did it!

Updating PHP

If you update PHP in the future then you will unfortunately need to repeat the process. It works best to delete (step 15) 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.

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