How to re-install PHP7 with ZTS enabled on Ubuntu 16.04?

I’ve installed the LAMP distribution on Ubuntu 16.04, and now I want to use threads in PHP7, but it wasn’t initially installed with ZTS enabled so now I need to reinstall it. Just wondering if there’s a guide to making this happen.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Man this seems like a huge amount of work for something so simple. Would you be able to recommend any other language that I could use for scripting with similar functionality to PHP but with threads already included?


If you want to run a test build using your configuration, you can install the required packages using:

apt-get -y install autoconf automake bc bison build-essential ccache cmake curl dh-systemd flex gcc geoip-bin google-perftools g++ haveged icu-devtools letsencrypt libacl1-dev libbz2-dev libcap-ng-dev libcap-ng-utils libcurl4-openssl-dev libdmalloc-dev libenchant-dev libevent-dev libexpat1-dev libfontconfig1-dev libfreetype6-dev libgd-dev libgeoip-dev libghc-iconv-dev libgmp-dev libgoogle-perftools-dev libice-dev libice6 libicu-dev libjbig-dev libjpeg-dev libjpeg-turbo8-dev libjpeg8-dev libluajit-5.1-2 libluajit-5.1-common libluajit-5.1-dev liblzma-dev libmhash-dev libmhash2 libmm-dev libncurses5-dev libnspr4-dev libpam0g-dev libpcre3 libpcre3-dev libperl-dev libpng-dev libpng12-dev libpspell-dev libpthread-stubs0-dev libreadline-dev libselinux1-dev libsm-dev libsm6 libssl-dev libtidy-dev libtiff5-dev libtiffxx5 libtool libunbound-dev libvpx-dev libvpx3 libwebp-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxml2-dev libxpm-dev libxslt1-dev libxt-dev libxt6 make nano perl pkg-config python-dev software-properties-common systemtap-sdt-dev unzip webp wget xtrans-dev zip zlib1g-dev zlibc

I just ran a test using the above and built PHP 7.2.x successfully using the same configure options as you noted in your reply.

Keep in mind, unlike repository packages, some things don’t work as you might expect. You’ll need to set these things up on your own.

For example:

php -v

…won’t work as it would with a repository package. You’ll need to export the path or use the full path when calling PHP from the CLI.

i.e. /etc/php7/bin/php -v

Also, there’s no service/systemd script for PHP-FPM, so you’d need to create that as well, otherwise you won’t be able to use:

service php7 start/stop/restart
systemctl start/stop/restart php7


This can be done and I’m running a test on my mini-guide before posting them so I can troubleshoot before handing them over.

Upfront, this will require rebuilding PHP from source and there are a few warnings that come with it.


Building from source is resource intensive and may fail on 512MB Droplets. It also takes a long time (20-30 minutes up to 1+ hours depending on resources), so be patient and don’t close out your connection.

I highly recommend building your package on a fresh droplet and transferring the package over to your existing. Why? The first command, build-dep is going to install numerous packages that most standard web servers do not need, thus creating more for you to update and manage.

Create a snapshot of your existing Droplet before you install the created package. You will need to uninstall the current before you will be able to install the new. Additionally, creating a backup before you attempt to install the new package means you have a security blanket that’ll allow you to restore to previous state, prior to the package being installed.

Lastly, please note that by building your own packages, you are now responsible for updating them. This means that where you previously could simply run apt-get -y upgrade and the latest patches and fixes would be installed if available from the maintainer, you will have to go through the process I detail each time you need to rebuild to include what was updated, etc (i.e. security patches, bug fixes, etc).

I’ll follow up shortly.