Compile PHP 5.x with Ubuntu20.04 Focal

2020-06-08
PHP
Ubuntu
Focal

Summary

If you’d like to use intl module (--enable-intl) and try to compile PHP 5.x on Ubuntu 20.04(Focal), it fails. Since Ubuntu 18.10 libicu installed via package manager (apt) does not include icu-config.

What you have to do is install appropriate version of ICU on Ubuntu 20.04 by yourself and specify it with --with-icu-dir configure option.

As far as I know, you need to install an old version of following two libraries in order to compile PHP 5.x on Ubuntu 18.10 or later.

  1. openssl (see my blog Compile PHP 5.x with Ubuntu18.04 Bionic)
  2. ICU (explained in this article)

Steps - Overview

  1. Download ICU version 60.x
  2. Install the ICU into version specific directory (i.e /usr/local/icu-x)
  3. Configure PHP 5.x with --with-openssl & --with-icu-dir options.

Steps - Detail

1. Download ICU version 60.x

http://site.icu-project.org/download/60#TOC-ICU4C-Download

1
2
3
$ cd /usr/local/src
$ wget https://github.com/unicode-org/icu/archive/release-60-3.tar.gz
$ tar xvzf icu-release-60-3.tar.gz

[Note] Version 61.x or higher will not work compiling PHP 5.x, make sure to download 60.x.

2. Install the ICU into version specific directory

1
2
3
4
5
6
$ cd /usr/local/src/icu-release-60-3/icu4c/source/
$ ./runConfigureICU Linux --prefix=/usr/local/icu-60
$ make -j4
$ sudo make install
$ /usr/local/icu-60/bin/icu-config --version
60.3

3. Configure PHP 5.4.45

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ 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 --enable-intl --enable-mbstring --with-openssl=/usr/local/openssl-1.0.2 --with-icu-dir=/usr/local/icu-60 --prefix=/usr/local/php54
$ make -j4
$ sudo make install
$ /usr/local/php54/bin/php -v
PHP 5.4.45 (cli) (built: Jun 8 2020 10:45:44)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
$ /usr/local/php54/bin/php -m | grep -P "openssl|intl"
intl
openssl

Misc

configure error message

Following message will be shown when you specify --enable-intl option with system default ICU.

1
2
3
4
checking whether to enable internationalization support... yes
checking for icu-config... no
checking for location of ICU headers and libraries... not found
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

libicu in Ubuntu 20.04

1
2
3
4
5
6
7
8
$ apt info libicu-dev
Package: libicu-dev
Version: 66.1-2ubuntu2
Priority: optional
Section: libdevel
Source: icu
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>

libicu deprecated icu-config since version 61.x. But if you don’t specify --disable-icu-config option, icu-config will be installed even with the latest version of ICU 66.1. I think Ubuntu intentionally specify --disable-icu-config to eliminate obsolete way of ICU uses.

[Download ICU 63 - ICU - International Components for Unicode]*(http://site.icu-project.org/download/63)

The icu-config tool has been deprecated. You can use the –disable-icu-config option to disable icu-config from being installed. Alternately, you can use –enable-icu-config to enable icu-config. In the future, icu-config will be disabled by default. (#62845)