Compile PHP 5.x with Ubuntu18.04 Bionic

2020-02-20
PHP
Ubuntu
Bionic

Ubuntu 18.04 LTS uses openssl-1.1.1 which is not compatible with PHP 5.x. This is how to compile PHP 5.x with Ubuntu 18.04 without downgrading system-wide openssl version.

Steps

  1. Download older openssl source.
  2. compile & install the openssl into version specific directory (i.e /usr/local/openssl-x.x.x)
  3. compile PHP 5.x with --with-openssl=/usr/local/openssl-x.x.x option.

Example

Compilation of PHP 5.4 with openssl-1.0.2.

1. Install openssl-1.0.2

1
2
3
4
5
6
7
8
9
$ cd /usr/local/src
$ wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
$ tar xvzf openssl-1.0.2u.tar.gz
$ cd openssl-1.0.2u
$ ./config --prefix=/usr/local/openssl-1.0.2 --openssldir=/usr/local/openssl-1.0.2
$ make -j4
$ sudo make install
$ /usr/local/openssl-1.0.2/bin/openssl version
OpenSSL 1.0.2u 20 Dec 2019

You can download other openssl version from https://www.openssl.org/source/old/

2. Install PHP 5.4.45

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ cd /usr/local/src
$ wget https://www.php.net/distributions/php-5.4.45.tar.gz
$ tar xvzf php-5.4.45.tar.gz
$ cd php-5.4.45
$ ./configure --with-openssl=/usr/local/openssl-1.0.2 --prefix=/usr/local/php54
$ make -j4
$ sudo make install
$ /usr/local/php54/bin/php -v
PHP 5.4.45 (cli) (built: Feb 20 2020 19:48:26)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
$ /usr/local/php54/bin/php -i | grep -i openssl
Configure Command => './configure' '--with-openssl=/usr/local/openssl-1.0.2' '--prefix=/usr/local/php54'
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.2u 20 Dec 2019
OpenSSL Header Version => OpenSSL 1.0.2u 20 Dec 2019
OpenSSL support => enabled