Skip to content

Instantly share code, notes, and snippets.

@bohanyang
Last active December 12, 2021 08:57
Show Gist options
  • Save bohanyang/63ad80f52f60c2194c44c598a93a2da2 to your computer and use it in GitHub Desktop.
Save bohanyang/63ad80f52f60c2194c44c598a93a2da2 to your computer and use it in GitHub Desktop.
The proper way to install a PHP extension
#!/bin/bash
set -eu
ver=8.1
api_ver=20210902
sapi=cli
ext=$1
ext_ver=$2
prio=30
[ $# -ge 3 ] && prio=$3
curl -fsSL -D - -O "https://pecl.php.net/get/$ext-$ext_ver.tgz"
tar xf "$ext-$ext_ver.tgz"
cd "$ext-$ext_ver"
"phpize$ver"
./configure --with-php-config="php-config$ver"
make -j"$(nproc)"
sudo cp "modules/$ext.so" "/usr/lib/php/$api_ver"
sudo tee "/etc/php/$ver/mods-available/$ext.ini" << EOF
; priority=$prio
extension=$ext.so
EOF
echo -e "\nsudo phpenmod -v $ver -s $sapi $ext\n"
@bohanyang
Copy link
Author

bohanyang commented Nov 18, 2020

sudo apt install php7.4-{cli,bcmath,bz2,curl,gmp,intl,mbstring,mysql,opcache,sqlite3,readline,xml,zip,dev,apcu,igbinary,xdebug} build-essential
# ext-event: sudo apt install libevent-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment