Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple PHP versions using phpenv and php-build

Multiple PHP versions using phpenv and php-build

Setting up environment variables

Create $HOME/.php_build_configure_opts file with the following contents:

--enable-debug --with-gettext --disable-fpm

Then update $HOME/.profile file as follows:

if [ -f $HOME/.php_build_configure_opts ]; then
  PHP_BUILD_CONFIGURE_OPTS=$(cat $HOME/.php_build_configure_opts)
  export PHP_BUILD_CONFIGURE_OPTS
fi

System deps

sudo apt install \
    bison \
    re2c \
    libxml2-dev \
    libbz2-dev \
    libssl-dev \
    libcurl4-gnutls-dev \
    pkg-config \
    libjpeg-dev \
    libpng-dev \
    libmcrypt-dev \
    libreadline-dev \
    libtidy-dev \
    libxslt-dev \
    libzip-dev \
    autoconf \
    libc-client-dev \
    libkrb5-dev \
    build-essential \
    libgmp-dev \
    libmagickwand-dev \
    libmagickcore-dev \
    linux-libc-dev \
    libyaml-dev \
    libmemcached-dev \
    libxpm-dev \
    libwebp-dev

Installation

Install phpenv

git clone git@github.com:hisayan/phpenv.git ~/.phpenv

Install php-build

git clone git@github.com:php-build/php-build.git ~/.phpenv/plugins/php-build

Install config-add plugin

git clone git@github.com:sergeyklay/phpenv-config-add.git ~/.phpenv/plugins/phpenv-config-add

Install pear-setup plugin

git clone git@github.com:sergeyklay/phpenv-pear-setup.git ~/.phpenv/plugins/phpenv-pear-setup

Usage

export PHP_BUILD_ZTS_ENABLE=on
export PHP_BUILD_XDEBUG_ENABLE=off
export PHP_BUILD_EXTRA_MAKE_ARGUMENTS=-j4
export PHP_BUILD_TMPDIR=~/src/php
mkdir -p $PHP_BUILD_TMPDIR

php-build --ini development 7.2.20 $(phpenv root)/versions/7.2.20-zts-debug/

Default configuration

cat <<EOT >> $(phpenv root)/versions/$(phpenv version-name)/etc/conf.d/999-defaults.ini
memory_limit=-1
variables_order=EGPCS
opcache.enable_cli=1
error_reporting=-1
display_errors=1
display_startup_errors=1
date.timezone=UTC
EOT

Install extensions

zephir_parser

git clone https://github.com/phalcon/php-zephir-parser.git /tmp/zephir-parser
cd /tmp/zephir-parser

phpenv local 7.2.20-zts-debug && phpenv rehash
phpize
./configure --with-php-config=$(phpenv which php-config) --enable-zephir-parser
make
make install

echo extension=zephir_parser.so > $(phpenv root)/versions/$(phpenv version-name)/etc/conf.d/zephir_parser.ini

gmp

cd $PHP_BUILD_TMPDIR/source/7.2.20/ext/gmp

phpenv local 7.2.20-zts-debug && phpenv rehash
phpize
./configure
make
make install

echo extension=gmp.so > "$(phpenv root)/versions/$(phpenv version-name)/etc/conf.d/gmp.ini"

PECL extensions

phpenv local 7.2.20-zts-debug && phpenv rehash
phpenv pear-setup

export PHP_PEAR_PHP_BIN=$(phpenv which php)

printf "\n" | pecl install --force igbinary 1> /dev/null
printf "\n" | pecl install --force imagick 1> /dev/null
printf "\n" | pecl install --force yaml 1> /dev/null
printf "\n" | pecl install --force memcached 1> /dev/null
printf "\n" | pecl install --force psr 1> /dev/null
printf "\n" | pecl install --force apcu_bc 1> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.