- Replacing the installed PHP with a custom compiled version with ZTS enabled (Pthreads requires it).
- Adding the Pthreads extension through PECL.
-
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
-
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.
-
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
-
Download the source files. Do not use
sudo
here.apt-get source php5
-
Go into the php5 source directory. Use
ls
to find the exact name of the directory.cd php5-5.6.30+dfsg
-
Open debian/rules in your favourite editor.
nano debian/rules
-
Find the
COMMON_CONFIG
variable and add a new line under it with:--enable-maintainer-zts \
-
Increment the package version number.
dch -i
Edit the top entry of the changelog if you wish but make sure you save either way.
-
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.
-
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 throughls
.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
-
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
-
Then download the source files.
apt-get source php5-json
-
Go into the source directory and build.
cd php-json-1.3.6 DEB_BUILD_OPTIONS=nocheck debuild -us -uc -b --no-lintian
-
Increment the package version number.
dch -i
Again, make sure to save.
-
Go back a directory and install.
cd .. sudo dpkg -i php5-json_1.3.6-1.1_amd64.deb
-
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
-
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 theexec
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/
-
Create a file at
/etc/php5/mods-available/pthread.ini
with the following contents; configuration for php pthreads module ; priority=20 extension=pthreads.so
-
Enable the Pthreads module.
sudo php5enmod pthreads
-
Restart apache2.
sudo /etc/init.d/apache2 restart
-
Cleanup by removing the directory we created:
cd .. rm -r php-dev
Well done, you did it!
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.
Another tip :
If you have error with
--no-lintian
option, like :You must use
--no-lintian
@ first :# DEB_BUILD_OPTIONS=nocheck debuild --no-lintian -us -uc -b