Technically Feasible

PHP7 beta1 build process for Debian Wheezy

Likeness of Michael Oldroyd
Michael Oldroyd
⚠️ This content was imported from a previous incarnation of this blog, and may contain formatting errors

PHP-logoLast weekend I decided to give PHP7 a try. Given it's beta, I had to compile from source. As I already run a stable package version, this guide doesn't cover the Debian packaging process. Instead we concentrate on installing PHP to an alternate directory.

Building PHP7 #

Firstly, install the build dependencies;

sudo apt-get -y build-dep php5
sudo apt-get -y install bison autoconf automake libtool pkg-config build-essential

I decided to download PHP from version control, and checkout the php-7.0.0beta1 tag;

git clone https://github.com/php/php-src.git
cd php-src/
git checkout php-7.0.0beta1
./buildconf --force

You have to force buildconf, as by default it believes itself to be a release package. Next, I saved my configure options to a shell script for replay;

./configure \
--prefix=/opt/php7 \
--enable-fpm \
--enable-mysqlnd \
--enable-opcache \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-gd \
--with-iconv \
--with-curl \
--with-mcrypt \
--enable-mbstring \
--enable-intl \
--enable-memcache \
--enable-zip \
--with-zlib

This will compile PHP7 with some basic options, including php-fpm and php-mysqlnd. Finally, we can kick off the build process;

make

Installing PHP7 / PHP-FPM #

sudo make install

Now PHP7 should be installed to /opt/php7.  We need to add PHP-FPM service management into Debian's init.d folder. PHP ships a init.d script which works fine, except you need to make a slight change;

sudo cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
sudo chmod +x /etc/init.d/php7-fpm
sudo sed -e 's/# Provides:\(\s*\)php-fpm/# Provides:\1php7-fpm/' -i /etc/init.d/php7-fpm
sudo update-rc.d php7-fpm defaults

Debian will trip up on the LSB Provides: line if you already run the php5-fpm package version. We need to switch the name to something different (i.e. php7-fpm). Above we use sed to change this value, which allows the update-rc.d command to run successfully.

Finally, I copy the php.ini-production example from the source distribution;

cp ./php.ini-production /opt/php7/lib/php.ini

Installing PHP7 Extensions #

This is where it gets interesting; we configured PHP to install to the /opt/php7 prefix, which leaves the Debian packaged version untouched. This does however complicate matters, as configure will use the package version of php-config. You will need to download packages manually, and configure them using the correct php-config. I required the imagick extension, which hasn't yet got a PHP7 compatible version in PECL;

sudo apt-get -y install libmagick++-dev
git clone https://github.com/mkoppanen/imagick.git
cd imagick
git checkout phpseven
/opt/php7/bin/phpize
./configure --with-php-config=/opt/php7/bin/php-config
make
sudo make install

Finally, add the extension to php.ini;

sudo sh -c "echo extension=imagick.so >> /opt/php7/lib/php.ini"

It's worth noting that the PECL extensions I checked don't seem yet to have been updated to facilitate the changes in the underlying Zend Engine.

Image of me

Michael Oldroyd

Michael is a Software Engineer working in the North West of England.