2

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.

paj
  • 1,177
  • 16
  • 33

2 Answers2

2

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
emont01
  • 3,010
  • 1
  • 22
  • 18
  • I have compiled latest openssl 1.1.1 and used --with-openssl-dir=/opt/openssl. PHP compiles but shows OpenSSL support => disabled (install ext/openssl). – paj Jun 28 '22 at 10:49
  • using openssl=shared results in the same compilation errors. It must be possible to compile 7.4 on 22.04. I am using Docker - but want to use an Ubuntu image... – paj Jun 28 '22 at 11:03
  • I just found some instructions in phpbrew's wiki, I have not tried it yet https://github.com/phpbrew/phpbrew/wiki/Troubleshooting#compiling-php74-with-the-openssl-extension-error-in-ubuntu-2204 – emont01 Jun 28 '22 at 14:42
  • 1
    this works in the PHP configure --with-openssl PKG_CONFIG_PATH=/opt/$OPENSSL_VERSION/bin/lib/pkgconfig – paj Jun 28 '22 at 16:08
  • I will update my response, I have also tried and I see that OpenSSL 1.1.1i works for 7.4.29 but 1.1.1p is required for 7.4.30 – emont01 Jun 28 '22 at 16:24
0

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
paj
  • 1,177
  • 16
  • 33