How to build and install PHP 5.6.10 from source on Debian VPS

How to build and install PHP 5.6.10 from source on Debian VPS

In this tutorial we will show you how to build and install PHP 5.6.10 from source on an Debian VPS.

We all know that PHP-5 is by default available in the Debian repositories. But many times there are situations where  for some crazy reason your application is not able to run on that particular version and you must upgrade it.

There are couple of ways to do that, and time time we will show you know to do that by using the PHP source package.


First thing to do is to log in to your Debian VPS as ROOT via SSH. Once you are in make sure that your Debian system is fully up-to-date by running the following commands in your terminal:

apt-get update
apt-get upgrade


Next, to avoid compilation errors about missing build dependencies install the following packages:

apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-dbg libmcrypt-dev libssl-dev libbz2-dev libjpeg-dev libfreetype6-dev libpng12-dev libxpm-dev libxml2-dev libpcre3-dev libbz2-dev libcurl4-openssl-dev libpng12-dev libxpm-dev libfreetype6-dev libmysqlclient-dev libt1-dev libgd2-xpm-dev libgmp-dev libsasl2-dev libmhash-dev unixodbc-dev freetds-dev libpspell-dev libsnmp-dev libtidy-dev libxslt1-dev libmcrypt-dev


Now let’s download the latest PHP 5.6.10 archive from some PHP mirror using the commands below:

wget -O /var/tmp/php-${PHP_VERSION}.tar.bz2 \${PHP_VERSION}.tar.bz2/from/this/mirror

Once the download of the archive is done extract the PHP source in the /opt/build directory. Since this directory do not exist we will need to create it manually. Type:

mkdir -p /opt/build

and extract the newly downloaded PHP archive:

tar -xvjpf /var/tmp/php-${PHP_VERSION}.tar.bz2 -C /opt/build

if you encounter an error like

tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

install bzip2 with:

apt-get install bzip2

and run the tar -xvjpf /var/tmp/php-${PHP_VERSION}.tar.bz2 -C /opt/build command again.

Once the PHP archive is extracted enter the directory:

cd /opt/build/php-${PHP_VERSION}


The configure options depend on your environment. In my case, I want to run PHP as FastCGI i.e PHP-FPM with many useful extensions enabled. You can run ./configure --help to find all available configure options. My configuration looks like the one below, so if you want to use it just copy + paste on your terminal and press “ENTER“:

./configure \
    --enable-fpm \
    --with-mcrypt \
    --enable-mbstring \
    --with-openssl \
    --with-mysql \
    --with-mysql-sock \
    --with-gd \
    --with-jpeg-dir=/usr/lib \
    --enable-gd-native-ttf  \
    --with-pdo-mysql \
    --with-libxml-dir=/usr/lib \
    --with-mysqli=/usr/bin/mysql_config \
    --with-curl \
    --enable-zip  \
    --enable-sockets \
    --with-zlib \
    --enable-exif \
    --enable-ftp \
    --with-iconv \
    --with-gettext \
    --enable-gd-native-ttf \
    --with-t1lib=/usr \
    --with-freetype-dir=/usr \
    --prefix=/opt/PHP-5.6 \
    --with-config-file-path=/opt/PHP-5.6/etc \
    --with-fpm-user=www-data \

this command will make PHP 5.6.10 installed within the /opt/PHP-5.6 directory.


if you encounter an error like

configure: error: freetype.h not found

even-though you installed libfreetype6-dev, then execute the following commands and try the ./configure again:

mkdir /usr/include/freetype2/freetype
ln -s /usr/include/freetype2/freetype.h /usr/include/freetype2/freetype/freetype.h


Now it’s time to compile PHP. So, run make to build the sources:


if the “make” command is not installed you can install it with:

apt-get install make

and run “make” again.

once the compilation is completed, optionally you may want to run make test to test the set-up:

make test


And finally, in the test goes well, run make install to install the compiled PHP to /opt/PHP-5.6

make install

That’s it.


To check the PHP version, run:

/opt/PHP-5.6/bin/php -v

PHP 5.6.10 (cli) (built: Jun 17 2015 09:33:19)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

If you’re one of our Linux VPS Hosting customers we can help you to build and install PHP 5.6.10 from source on your virtual server for you free of charge. Just contact us and some of our experts will complete your request immediately.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>