Build and Install latest PHP cURL extenstion on RunCloud

In this example we’re gonna build latest cURL on Ubuntu 16.04

## Create path for custom builds
## Don't use system paths to avoid conflicts
sudo mkdir /usr/myownbuilds

## Create a temporary directory
## And do all stuff there
mkdir ~/mytmpdir

## nghttp2 is required by cURL to use http/2 protocol
## so we need to build it first
cd ~/mytmpdir
VERSION=1.40.0
wget https://github.com/nghttp2/nghttp2/archive/v${VERSION}.tar.gz
tar -xf nghttp2-${VERSION}.tar.gz
cd nghttp2-${VERSION}
autoreconf -i
automake
autoconf
./configure --prefix=/usr/myownbuilds
make -j$(nproc)
sudo make install

## OpenSSL required by cURL to use https
## so we need to build it too.
cd ~/mytmpdir
VERSION=1_1_1g
wget https://github.com/openssl/openssl/archive/OpenSSL_${VERSION}.tar.gz
tar -xf OpenSSL_${VERSION}.tar.gz
cd openssl-*
./config --prefix=/usr/myownbuilds --openssldir=/usr/myownbuilds shared zlib
make -j$(nproc)
sudo make install

## Brotli required by cURL
## so we need to build it too.
cd ~/mytmpdir
git clone --depth=1 https://github.com/google/brotli.git
cd brotli
./bootstrap
./configure --prefix=/usr/myownbuilds
make -j$(nproc)
sudo make install

## Add pkgconfig to the PKG_CONFIG_PATH
## This will tell pkgconfig to look libs also in this directory
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/myownbuilds/lib/pkgconfig

## Now build cURL, change version number.
## Make sure /usr/myownbuilds/lib/pkgconfig is on PKG_CONFIG_PATH
cd ~/mytmpdir
wget https://github.com/curl/curl/archive/curl-7_70_0.tar.gz
tar -xf curl-7.70.0.tar.gz
cd curl-7.70.0
./configure \
    --prefix=/usr/myownbuilds \
    --with-nghttp2=/usr/myownbuilds \
    --with-ssl \
    --with-brotli
make -j$(nproc)
sudo make install

Now cURL and its libraries are successfully built. Now we need to build php-curl extension.

## Make sure /usr/myownbuilds/lib/pkgconfig is on PKG_CONFIG_PATH
## Other wise build will fail.
cd ~/mytmpdir
VERSION=7.4.6
wget https://github.com/php/php-src/archive/php-${VERSION}.tar.gz
tar -xf php-${VERSION}.tar.gz
cd php-src-php-${VERSION}/ext/curl

PHPRC_VERSION="php74rc"
/RunCloud/Packages/$PHPRC_VERSION/bin/phpize
./configure --with-php-config=/RunCloud/Packages/$PHPRC_VERSION/bin/php-config
make -j$(nproc)

## curl.so should be here
cd ../../modules

## move curl.so
sudo mkdir /usr/myownbuilds/$PHPRC_VERSION-ext
mv curl.so /usr/myownbuilds/$PHPRC_VERSION-ext

## Modify extension path on curl.ini
sudo nano /etc/$PHPRC_VERSION/conf.d/curl.ini
extension=/usr/myownbuilds/php74rc-ext/curl.so

## Verify it's working.
## Check using: php -i | grep "curl info" -i
## Once verfied, reload fpm.
systemctl reload $PHPRC_VERSION-fpm