Skip to content

Instantly share code, notes, and snippets.

@smola
Last active July 12, 2023 17:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smola/a01be46aad2704b3844620a95301b512 to your computer and use it in GitHub Desktop.
Save smola/a01be46aad2704b3844620a95301b512 to your computer and use it in GitHub Desktop.
Install old OpenSSL for use with PHPBrew and old PHP versions (e.g. 5.3)
#!/bin/sh
#
# Build old OpenSSL for usage in old PHP builds
# (e.g. PHP 5.3).
#
# This solution was originally found at:
# https://gist.github.com/marulitua/f8932064ec5bfe6a5be9fadac7c5a141
#
# Relevant discussions:
# https://github.com/phpbrew/phpbrew/issues/418
# https://www.php.net/manual/en/openssl.installation.php#115909
#
# This script is tested with Ubuntu 20.04, but
# it should work on most Linux systems that work
# with phpbrew.
#
set -e
PHPBREW_HOME="${PHPBREW_HOME:-$HOME/.phpbrew}"
if [ ! -d "${PHPBREW_HOME}" ]; then
echo "${PHPBREW_HOME} does not exist"
exit 1
fi
HACKS_DIR="${PHPBREW_HOME}/hacks"
HACK_OPENSSL_DIR="${HACKS_DIR}/openssl"
OPENSSL_TARBALL="openssl-1.0.2o.tar.gz"
OPENSSL_BASENAME="${OPENSSL_TARBALL%.tar.gz}"
OPENSSL_URL="https://www.openssl.org/source/${OPENSSL_TARBALL}"
OPENSSL_MD5="44279b8557c3247cbe324e2322ecd114"
OPENSSL_BUILD_DIR="${HACK_OPENSSL_DIR}/${OPENSSL_BASENAME}"
OPENSSL_DIR="${HACK_OPENSSL_DIR}/openssl"
mkdir -p "${HACK_OPENSSL_DIR}"
cd "${HACK_OPENSSL_DIR}"
if [ ! -f "${OPENSSL_TARBALL}" ]; then
wget "${OPENSSL_URL}" -O "${OPENSSL_TARBALL}"
fi
if ! echo "${OPENSSL_MD5} ${OPENSSL_TARBALL}" | md5sum --check ; then
echo "md5sum (${OPENSSL_MD5}) check failed for ${OPENSSL_TARBALL}"
exit 1
fi
tar xzf "${OPENSSL_TARBALL}"
cd "${OPENSSL_BUILD_DIR}"
./config -fPIC shared --prefix="${HACK_OPENSSL_DIR}" --openssldir="${OPENSSL_DIR}"
make -j $(nproc)
make test
make install
ln -sf "${HACK_OPENSSL_DIR}/lib" "${HACK_OPENSSL_DIR}/lib/x86_64-linux-gnu"
echo
echo "${OPENSSL_BASENAME} is ready at ${OPENSSL_DIR}"
echo "Now you can use it in a phpbrew build:"
echo " phpbrew install 5.3 +openssl=${HACK_OPENSSL_DIR}"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment