Cannot compile PHP 7.4.30 on Ubuntu 22.04LTS

Viewed 153

I have an issue trying to manually compile PHP 7.4.x on Ubuntu Server 22.04LTS.

There seems to be a compatibility problem between PHP 7.4 and OpenSSL 3.0 as the php compilation fails with various OSSL_DEPRECATEDIN_3_0 errors.

If PHP7.4 has no OpenSSl 3 support is it still possible to compile it manually on 22.04LTS?

It compiles successfully on 18.04LTS.

2 Answers

In short: you can't! You need to compile OpenSSL 1.1 from source.

If I may suggest an alternative! check out docker

I have being trying to do the same to install PHP 7.4.30; the problem is caused by Ubuntu's 22.04 usage of libssl3, libssl1.1 (the one we need) was present until impish (21.10)

ubuntu package libssl1.1

In a response at serverfault.com its mentioned that:

You can use --with-openssl or --with-openssl-dir to solve this problem indicating where your custom openssl build is, for example if you downloaded and built it from source in /opt/openssl you could add the following to your build options

--with-openssl-dir=/opt/openssl

Digging through some old SO answers I found this example:

phpbrew install 7.1 +default +openssl=shared -- --with-openssl-dir=/openssl/openssl

After checking the official phpbrew wiki I found the following steps to compile and install OpenSSL 1.1 from source in Ubuntu 22.04:

cd $HOME
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar xzf $HOME/openssl/openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
./Configure --prefix=$HOME/openssl-1.1.1i/bin -fPIC -shared linux-x86_64
make -j 8 
make install

Is worth to mention that for me:

  1. OpenSSL 1.1.1i works for php 7.4.29
export PKG_CONFIG_PATH=$HOME/openssl-1.1.1i/bin/lib/pkgconfig && \
phpbrew install 7.4.29 +default
  1. OpenSSL 1.1.1p works for php 7.4.30
export PKG_CONFIG_PATH=$HOME/openssl-1.1.1i/bin/lib/pkgconfig && \
phpbrew install 7.4.30 +default

For anyone using an Ubuntu 22.04 Docker image here is the build for OpenSSL 1.1.1p and the php compilation options:

ENV OPENSSL_VERSION openssl-1.1.1p
RUN set -xe \
    && curl -fSL "https://www.openssl.org/source/$OPENSSL_VERSION.tar.gz" -o "$OPENSSL_VERSION.tar.gz" \
    && ls -al \
    && tar xzf $OPENSSL_VERSION.tar.gz \
    && cd $OPENSSL_VERSION \
    && ./Configure --prefix=/opt/$OPENSSL_VERSION/bin -fPIC -shared linux-x86_64 \
    && make -j 8  \
    && make install \
    && export PKG_CONFIG_PATH=/opt/$OPENSSL_VERSION/bin/lib/pkgconfig

Add the following to the php compilation configure options

--with-openssl \
PKG_CONFIG_PATH=/opt/$OPENSSL_VERSION/bin/lib/pkgconfig \

PHP 7.4.30 (cli) (built: Jun 28 2022 15:51:41) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies

 openssl
 
 OpenSSL support => enabled OpenSSL
 Library Version => OpenSSL 1.1.1p 21 Jun 2022
 OpenSSL Header Version => OpenSSL 1.1.1p  21 Jun 2022
 Openssl default config => /opt/openssl-1.1.1p/bin/ssl/openssl.cnf
Related