Skip to content

Instantly share code, notes, and snippets.

@Chekote
Last active October 7, 2022 15:41
Show Gist options
  • Save Chekote/bb51e4057f44e64b0905d60f77fd73c2 to your computer and use it in GitHub Desktop.
Save Chekote/bb51e4057f44e64b0905d60f77fd73c2 to your computer and use it in GitHub Desktop.
How to compile a PHP extension into a shared module for any PHP version
# How to compile a PHP extension into a shared module for any PHP version
# download and decompress required PHP version source (e.g. 5.6.30). See http://php.net/releases/
wget http://php.net/get/php-5.6.30.tar.bz2/from/this/mirror -O php-5.6.30.tar.bz2
tar xvf php-5.6.30.tar.bz2
# compile and install PHP to temporary location (e.g. ~/php-install)
cd php-5.6.30/
time ./configure --prefix=${HOME}/php-install
make -j 8
make install
# check for phpize and add to PATH
cd ~/php-install/
export PATH=./bin:$PATH
export PATH=$PWD/bin:$PATH
which phpize
phpize --version
# compile PHP extension from PHP source (e.g. bcmath)
cd ~/php-5.6.30/ext/bcmath
phpize
./configure
make -j4
find . -name bcmath.so
# compile PHP extension from different repo (e.g. Redis). See https://github.com/phpredis/phpredis
cd
git clone https://github.com/phpredis/phpredis.git
cd ~/phpredis/
phpize
./configure
make -j4
find . -name redis.so
# move extension and configure PHP (e.g bcmath)
cp ~/php-5.6.30/ext/bcmath/modules/bcmath.so /usr/lib/php/20131226/
echo "extension=bcmath.so" > /etc/php/5.6/mods-available/bcmath.ini
ln -s /etc/php/5.6/mods-available/bcmath.ini /etc/php/5.6/cgi/conf.d/25-bcmath.ini
php -i | grep bcmath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment