Skip to content

Instantly share code, notes, and snippets.

@Divi
Last active May 19, 2021 00:43
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save Divi/9696838 to your computer and use it in GitHub Desktop.
Save Divi/9696838 to your computer and use it in GitHub Desktop.
Compile PHP Thread Safe & pthreads extension
#!/usr/bin/env bash
# PARAMETERS
# ----------
# PHP
# ---
PHP_TIMEZONE="UTC"
PHP_DIRECTORY="/etc/php5ts"
# Update the box release repositories
# -----------------------------------
apt-get update
# Essential Packages
# ------------------
apt-get install -y build-essential git-core vim curl
# PHP with Thread Safe build
# --------------------------
git clone https://github.com/php/php-src.git /tmp/php-src
cd /tmp/php-src
git checkout tags/php-5.5.15
apt-get install -y make autoconf re2c bison
# If you add some configuration command, add the dependancies here
apt-get install -y libicu-dev libmcrypt-dev libssl-dev libcurl4-openssl-dev libbz2-dev libxml2-dev libpng-dev libjpeg-dev libedit-dev
./buildconf --force
./configure --prefix=$PHP_DIRECTORY --with-config-file-path=$PHP_DIRECTORY --with-config-file-scan-dir=$PHP_DIRECTORY/conf.d --disable-all --enable-maintainer-zts --with-curl --with-openssl --with-gd --enable-gd-native-ttf --enable-intl --enable-mbstring --with-mcrypt --with-mysqli=mysqlnd --with-zlib --with-bz2 --enable-exif --with-pdo-mysql=mysqlnd --with-libedit --enable-zip --enable-pdo --enable-pcntl --enable-sockets --enable-mbregex --with-tsrm-pthreads
# If you need FPM mode, add : --enable-fpm --with-fpm-group=www-data --with-fpm-user=www-data
make
make install
cp php.ini-production /etc/php5ts/php.ini
# pthreads Extension build
# ------------------------
git clone https://github.com/krakjoe/pthreads.git /home/pthreads
cd /home/pthreads
apt-get install -y php5-dev
phpize
./configure --with-php-config=$PHP_DIRECTORY/bin/php-config
make
make install
mkdir $PHP_DIRECTORY/conf.d
echo "extension=pthreads.so" > /etc/php5ts/conf.d/pthreads.ini
# Setting PHP configurations
# --------------------------
# Date timezone
sed 's#;date.timezone\([[:space:]]*\)=\([[:space:]]*\)*#date.timezone\1=\2\"'"$PHP_TIMEZONE"'\"#g' $PHP_DIRECTORY/php.ini > $PHP_DIRECTORY/php.ini.tmp
mv $PHP_DIRECTORY/php.ini.tmp $PHP_DIRECTORY/php.ini
# Error messages
sed 's#display_errors = Off#display_errors = On#g' $PHP_DIRECTORY/php.ini > $PHP_DIRECTORY/php.ini.tmp
mv $PHP_DIRECTORY/php.ini.tmp $PHP_DIRECTORY/php.ini
sed 's#display_startup_errors = Off#display_startup_errors = On#g' $PHP_DIRECTORY/php.ini > $PHP_DIRECTORY/php.ini.tmp
mv $PHP_DIRECTORY/php.ini.tmp $PHP_DIRECTORY/php.ini
sed 's#error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT#error_reporting = E_ALL#g' $PHP_DIRECTORY/php.ini > $PHP_DIRECTORY/php.ini.tmp
mv $PHP_DIRECTORY/php.ini.tmp $PHP_DIRECTORY/php.ini
@3esmit
Copy link

3esmit commented Sep 24, 2015

Thank you for sharing this script.

@caneroner
Copy link

Hi,

Thank you for the script, it needs to be update for bison and pthreads version otherwise it gives errors.
Bison 3 is not compatible with PHP5.5.X, so Bison 2.7 should be installed.
Pthreads current version is 3 and it's for PHP7, 2.0.10 branch should be used for PHP5.X

@louis-aubert
Copy link

👍

@pathikvejani
Copy link

I can't see any changes after running this script.

@pathikvejani
Copy link

I can't see pthread module in listing.

@sam452
Copy link

sam452 commented Jun 20, 2016

Thank you also for posting this. Stuck on recipe for target 'php_pthreads.lo' failed. Not found clues yet.

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