opensslphp-7.4php-opensslubuntu-22.04

Cannot compile PHP 7.4.30 on Ubuntu 22.04LTS


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.


Solution

  • 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