Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

3esmit commented Sep 24, 2015

Thank you for sharing this script.

@caneroner

This comment has been minimized.

caneroner commented Sep 28, 2015

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

This comment has been minimized.

louis-aubert commented Feb 26, 2016

👍

@pathikvejani

This comment has been minimized.

pathikvejani commented Apr 6, 2016

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

@pathikvejani

This comment has been minimized.

pathikvejani commented Apr 6, 2016

I can't see pthread module in listing.

@sam452

This comment has been minimized.

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