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)

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:
- 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
- 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