Enable ZTS Support on Ubuntu 14.04

November 10, 2014 20.7k views

Hi,
i've installed everything that regards PHP from the repository. I've installed php5-dev package and all other dependencies to run pthreads on my droplet.
I don't understand how to enable the ZTS on it...what should i do?
Do i have to download PHP5 from another source? Thanks.

4 Answers

ZTS support is a configure time option and can not be enabled at run time. You'll need to build php yourself with the --enable-maintainer-zts flag in order to enable it.

One way to do this is to modify the existing package and rebuild it. First we'll need to install and download a few things:

Install the build dependencies:

  • sudo apt-get build-dep php5

Install the developer tools:

  • sudo apt-get install devscripts

Download the source:

  • apt-get source php5

Now enter the source directory and edit the debian/rules file:

  • cd php5-5.5.9+dfsg/ # The version will be different depending on the Ubuntu release
  • nano debian/rules

Find the section starting with COMMON_CONFIG=--build=$(DEB_BUILD_GNU_TYPE) \ and add the following configure flags:

  • --enable-maintainer-zts \
  • --enable-pthreads \

Then we want to bump the version number for the package, so that it is higher than the version of PHP in the repository. Run dch -i and create a new changelog entry:

  • php5 (5.5.9+dfsg-1ubuntu4.5+zts1) trusty; urgency=medium
  • * Rebuild with ZTS support.
  • -- You <doesnt@matter.com> Mon, 10 Nov 2014 13:14:32 -0500

Now the package can be built using the command:

  • DEB_BUILD_OPTIONS=nocheck debuild

This will take quite awhile and will also require some memory. If you're on a 512mb server, you'll probably need to add some swap.

It will produce a number of packages in the parent directory:

  • cd ..
  • ls *deb

You can now install the individual packages with sudo dpkg -i pakage_name.deb or all of them with sudo dpkg -i *deb

by Justin Ellingwood
Swap space can be used as an "overflow" area for your system when you run out of RAM. The operating system can store data that would normally be kept in RAM on the hard drive in a specially formatted file. In this guide, we'll demonstrate how to create and use one of these files in Ubuntu 14.04.
  • Really nice!
    After doing that by installing all packages, pthreads work, but it gives me a fatal error:

    <b>Fatal error</b>: Call to undefined function json_encode() in <b>/var/www...

    How can i re-enable JSON support?
    Thanks.

  • Unfortunately, once you start installing/rebuilding key packages like php from source you see the bits that distro developers take care of for you. Libraries may have to be rebuilt to work with the php package you built. You can do with with steps similar to ones above but with the php5-json package.

  • I made

    apt-get source php5-json
    

    Then did

    dch -i
    

    and then DEB_BUILD_OPTIONS=nocheck debuild

    That's what i've got

    dpkg-buildpackage -rfakeroot -D -us -uc
    dpkg-buildpackage: warning: using a gain-root-command while being root
    dpkg-buildpackage: source package php-json
    dpkg-buildpackage: source version 1.3.2-2ubuntu1
    dpkg-buildpackage: source distribution UNRELEASED
    dpkg-buildpackage: source changed by root <root@Tapebox.cloudapp.net>
     dpkg-source --before-build php-json-1.3.2
    dpkg-buildpackage: host architecture amd64
    dpkg-checkbuilddeps: Unmet build dependencies: libjson-c-dev (>= 0.11-3~)
    dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting
    dpkg-buildpackage: warning: (Use -d flag to override.)
    debuild: fatal error at line 1364:
    dpkg-buildpackage -rfakeroot -D -us -uc failed
    

    What can i do?

    edited by asb
  • Fixed it, i just had to do

    sudo apt-get install libjson-c-dev
    

    and retry all.
    Thank you very very much for the help :)

  • Hallo!,

    By running DEB_BUILD_OPTIONS=nocheck debuild i get an error:

    /usr/src/php5-5.5.9+dfsg/ext/date/php_date.c:3775:3: warning: passing argument 3 of 'php_error_docref0' makes integer from pointer without a cast [enabled by default]
       php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
       ^
    In file included from /usr/src/php5-5.5.9+dfsg/ext/date/php_date.c:21:0:
    /usr/src/php5-5.5.9+dfsg/main/php.h:309:13: note: expected 'int' but argument is of type 'char *'
     PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
                 ^
    /usr/src/php5-5.5.9+dfsg/ext/date/php_date.c:3775:3: error: too few arguments to function 'php_error_docref0'
       php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
       ^
    In file included from /usr/src/php5-5.5.9+dfsg/ext/date/php_date.c:21:0:
    /usr/src/php5-5.5.9+dfsg/main/php.h:309:13: note: declared here
     PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
                                          ^
        make[1]: *** [ext/date/php_date.lo] Error 1
        make[1]: Leaving directory `/php5-5.5.9+dfsg/apache2-build'
        make: *** [build-apache2-stamp] Error 2
        dpkg-buildpackage: error: debian/rules build gave error exit status 2
        debuild: fatal error at line 1364:
        dpkg-buildpackage -rfakeroot -D -us -uc failed
    

    I Have no Idea to solve it.

    Please help.

    Thank You

    edited by asb
  • Thank you very much @asb. I followed your guide step by step but I'm stuck in the DEB_BUILD_OPTIONS=nocheck debuild command. I'm not able to build the package, this is the error I'm getting:

    /home/forge/tmp/php5-5.5.9+dfsg/ext/date/php_date.c:3775:3: error: too few arguments to function ‘php_error_docref0’
       php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
       ^
    In file included from /home/forge/tmp/php5-5.5.9+dfsg/ext/date/php_date.c:21:0:
    /home/forge/tmp/php5-5.5.9+dfsg/main/php.h:309:13: note: declared here
     PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
                 ^
    make[1]: *** [ext/date/php_date.lo] Error 1
    make[1]: Leaving directory `/home/forge/tmp/php5-5.5.9+dfsg/apache2-build'
    make: *** [build-apache2-stamp] Error 2
    dpkg-buildpackage: error: debian/rules build gave error exit status 2
    debuild: fatal error at line 1364:
    dpkg-buildpackage -rfakeroot -D -us -uc failed
    

    I've tried with @sintsov fix:

    sudo dpkg-reconfigure tzdata
    

    But nothing happens. Any ideas on how to fix it? I really need to implement ZTS in order to get PHP multithreading.

    Best!

peteinba,
i fixed this problem

sudo dpkg-reconfigure tzdata

you need to choose your local timezone and retry all.

Hi I have the same error

php_error_docref(NULL, E_ERROR, "Timezone initialization failed");

and I have run

sudo dpkg-reconfigure tzdata

but php not compile, so, do you have any comments?

Have another answer? Share your knowledge.