How to install PHP 5.6.40 as an optional version on Debian 9 (Stretch) perfect server

botond published 2019/02/19, k - 01:08 time

The 1. page content

 

Introductory

Debian 9 (Stretch) Distribution a PHP Includes version 7.0 by default. The main versions of PHP are not fully compatible with each other, so it is often the case that web pages running on the server require a newer or even older version of PHP. In this description, we will install the current latest version of PHP 5.6, 5.6.40, as an optional PHP version for a Debian 9 (Stretch) based server, which will be installed by FastCGI and PHP-FPM modes can then be operated. This will allow it to be used for websites in addition to the default version of PHP in the distribution.

I've made one before another description, in which I installed 8 PHP on a Debian 7.1 (Jessie) based server.

 

 

Prerequisites

You need a Debian 9 running this tutorial ISPConfig server environment. This installation is my Debian 9 (Stretch) is the perfect server for 1.0 I make it on version.

 

Preparation

Let's upgrade to Debian first package store database and packages. It is issued as root as usual apt-get commands:

apt-get update
apt-get upgrade

We will install this PHP as an optional version, which means that you will be able to work with the default PHP in the distribution, for the website that needs it. Since Debian 9 no longer includes PHP 5.6 and will not be installed by default, we do not need to install it from packages as usual, but compile it from its source code.

Before compiling, you will need a lot of preparation and configuration to build a compatible environment for PHP 5.6 similar to Debian 8. In addition, during pre-compilation configuration, many more parameters need to be set so that the web hosts on the server can use it as a fully functional and independent PHP system.

Install packages needed for translation

Translating PHP requires development and translation tools. Install the build-essentialautoconf, pkg-config packages:

apt-get -y install build-essential  autoconf  pkg-config

Then install the development packages for the PHP environment, which are also needed for translation:

apt-get -y install \
    libfcgi-dev \
    libfcgi0ldbl \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libssl-dev \
    libc-client2007e \
    libc-client2007e-dev \
    libxml2-dev \
    libbz2-dev \
    libcurl4-openssl-dev \
    libjpeg-dev libpng-dev \
    libfreetype6-dev \
    libkrb5-dev \
    libpq-dev \
    libxml2-dev \
    libxslt1-dev

For the sake of clarity, I split the command into several lines. You can run it in the same way when copied.

Creating the necessary links

Two links are needed to compile the PHP IMAP module:

ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
cd /usr/include
ln -s x86_64-linux-gnu/curl

Installing older OpenSSL

In the Debian 9 distribution OpenSSL version (1.1.0) is too new for PHP 5.6, so we need to install the older version (1.0.1t), which is basically part of the Debian 8 (Jessie) distribution. Since Debian 9 does not include this package, we need to compile it from its source code. Of course, the older version of OpenSSL will be installed as a secondary to the existing one, which will only be used by PHP 5.6 and will not interfere with the default version.

Download OpenSSL version 1.0.1t from its official site and unpack:

cd /tmp
wget "https://www.openssl.org/source/old/1.0.1/openssl-1.0.1t.tar.gz"
tar xzf openssl-1.0.1t.tar.gz 

Create the destination directory:

mkdir /opt/openssl

Enter the source directory and configure:

cd openssl-1.0.1t
./config shared --prefix=/opt/openssl

Compiling dependencies for the source:

make depend
Az in the original description there was no make depend command, without me the next make command stopped with an error. So I put this in front of the make, after that it turned nicely.
It has also been written in the comments below that conditions have changed in Debian 9 since this description was written. This is always worth considering when writing an older description.

Now you can compile OpenSSL:

make

Then, if it ran smoothly, the installation might come:

make install

Create a link and keep OpenSSL up to date root certificate package download a wget command:

ln -s /opt/openssl/lib /opt/openssl/lib/x86_64-linux-gnu
wget -O /opt/openssl/ssl/cert.pem "http://curl.haxx.se/ca/cacert.pem"

To create additional links so that PHP 5.6 can access the libcrypto and libssl libraries:

ln -s /opt/openssl/lib/libcrypto.so.1.0.0 /usr/lib/x86_64-linux-gnu/
ln -s /opt/openssl/lib/libssl.so.1.0.0 /usr/lib/x86_64-linux-gnu/
ln -fs /opt/openssl /usr/local/ssl

Finally, delete the transitional items:

rm -rf /tmp/openssl*

 

 

Make the FreeType library available

Something was wrong with the freetype2 linking section as originally described, so I looked around in Debian 8 to see how this freetype2 library is there.

In Debian 8 a / Usr / include / freetype2 / directory contains the FreeType header files directly, and a config subdirectory. And in Debian 9, the same structure is inside one directory level: / Usr / include / freetype2 / freetype /.

This difference is a dpkg command can be used to check both systems:

dpkg -L libfreetype6-dev | grep "/usr/include"

There are two possible solutions here: Either flip the files and the config directory up one directory level, or give PHP the correct directory for FreeType support:

[...]
    --with-freetype-dir=/usr/include/freetype2/freetype
[...]

I think the latter is more reasonable, so we will configure this in PHP.

This would prepare you for downloading, configuring, translating and installing PHP.

 

Download PHP 5.6

At the time of writing, 5.6 is the latest in the 5.6.40 branch of PHP, so I’ll be working on that throughout. This version may be updated later, so it is a good idea to go through the newer version when reading this description.

Create the installation destination directory:

mkdir -p /opt/php-5.6.40
It is a good idea to name the target directory with the exact version number, because who knows, a fix may be added to a newer version of PHP 5.6 later, which is why we will consider it worthwhile to compile the newer one on our server as well. This way, our libraries can stay organized. So it’s worth thinking about a bigger perspective.

Create a temporary directory for the source and translation, and enter it:

mkdir /usr/local/src/php-5.6-build
cd /usr/local/src/php-5.6-build

Download the PHP Editions Download Page the 5.6.40 source package, or if it has been updated since this description was made. I choose the Austrian mirror here, but it may be although the one I to fill.

wget http://at2.php.net/get/php-5.6.40.tar.gz/from/this/mirror -O php-5.6.40.tar.gz

Unpack:

tar -xzf php-5.6.40.tar.gz

 

 

Translation and installation

configuration

Before compiling, you must configure the source, which prepares the software for compilation on that particular hardware. Among other things, we need to give him a lot of parameters, which will give us a complete, working system.

Enter the source directory:

cd /usr/local/src/php-5.6-build/php-5.6.40

All configuration options, switches can be viewed by the following command:

./configure --help

Here is a ready-made configuration, which I compiled based on the original description and taking into account the changes that occurred here:

./configure\
    --prefix=/opt/php-5.6.40 \
    --with-pdo-pgsql \
    --with-zlib-dir \
    --with-freetype-dir \
    --enable-mbstring \
    --with-libxml-dir=/usr \
    --enable-soap \
    --enable-calendar \
    --with-curl \
    --with-mcrypt \
    --with-gd \
    --with-zlib \
    --with-pgsql \
    --disable-rpath \
    --enable-inline-optimization \
    --with-bz2 \
    --enable-sockets \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-pcntl \
    --enable-mbregex \
    --enable-exif \
    --enable-bcmath \
    --with-mhash \
    --enable-zip \
    --with-pcre-regex \
    --with-pdo-mysql \
    --with-mysql \
    --with-mysqli \
    --with-mysql-sock=/var/run/mysqld/mysqld.sock \
    --with-jpeg-dir=/usr \
    --with-png-dir=/usr \
    --enable-gd-native-ttf \
    --with-openssl=/opt/openssl \
    --with-openssl-dir=/opt/openssl \
    --with-libdir=/lib/x86_64-linux-gnu \
    --enable-ftp \
    --with-kerberos \
    --with-gettext \
    --with-xmlrpc \
    --with-xsl \
    --enable-opcache \
    --with-fpm-user=www-data \
    --with-fpm-group=www-data \
    --enable-fpm

So this configuration includes almost everything you might need in a full PHP, except for one thing: IMAP support.

In Debian 9, IMAP is too recent for PHP 5.6. An older version can still be compiled for it, but it would require even more old dependencies, which already pose a security risk. On the other hand, if you install PHP 9 as an optional version on a Debian 5.6 server, IMAP is not required, as it is included in the default PHP version 7 of the distribution, so you can run webmail clients with that version or anything else that requires IMAP. So on this server, we only use PHP 5.6 as a lifeline if, for example, we need to run an old web page that was written for PHP 5 at the time.

I ran this configuration without any errors, so the next step might come.

Translation

You can compile the source of the prepared software package with the make command, remaining in the source directory (/ usr / local / src / php-5.6-build / php-5.6.40). I'm curious about the time command, so I can measure the exact run time:

time make

He threw quite a few warnings, but there was no error in it, and he ran for 9 minutes 42 seconds a On a VirtualBox machine. The host machine is an Intel I7-3770 CPU.

Installation

And finally, there is the installation, which puts PHP in its final place:

make install

Thus, the / Opt / php-5.6.40 / our PHP 5.6 system has been placed in the directory.

Control

You can also verify the successful installation by using the command line (CLI) Via PHP:

/opt/php-5.6.40/bin/php --version

And the appropriate output is:

PHP 5.6.40 (cli) (built: Feb 18 2019 16:47:39) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

 

A next page we will continue with the post-install configuration of PHP 5.6.40.

 

 

Navigation

This description consists of several pages: