Compile PHP From Scratch on Ubuntu WSL With PHPBrew

wsl --set-version <Distro> 2
wsl --set-default-version 2
wsl -l -v
NAME STATE VERSION
* Alpine Running 2
Ubuntu-18.04 Running 2
docker-desktop Running 2
docker-desktop-data Running 2

PHPBrew: A Quick Intro

  • The PHP-FPM Docker web service that serves my Drupal workload runs on PHP 7.3.14, the latest stable version.
  • The latest Long Term Support (LTS) of Ubuntu distributed through the Windows Store only comes with PHP 7.2.24.
  • I would die of hunger as a sports writer (or as a writer, period).
  1. This article: Blast from the Past (Feb 1, 2019) — by Arne Blankerts, Stefan Priebsch, and none other than Sebastian Bergmann himself — the man that brought us PHPUnit, amongst other important PHP tools.
  2. The fact that PHPBrew does not seem to offer a signature for verifying the integrity of it’s PHAR archive.
$ curl -L https://pear.php.net/go-pear.phar | php
# or
$ wget https://pear.php.net/go-pear.phar && php go-pear.phar
curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.pharchmod +x phpbrew.phar

# Move the file to some directory within your $PATH
sudo mv phpbrew.phar /usr/local/bin/phpbrew

Installing PHP 7.3 on Ubuntu for WSL 2 with PHPBrew

curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.pharchmod +x phpbrew.phar

# Move the file to some directory within your $PATH
sudo mv phpbrew.phar /usr/local/bin/phpbrew
sudo apt-get install -y build-essential bzip2 php7.2 php-bz2
sudo yum install php php-devel php-pear bzip2-devel yum-utils bison re2c libmcrypt-devel libpqxx-devel libxslt-devel pcre-devel libcurl-devel libgsasl-devel openldap-devel httpd-devel readline-devel
apt-cache search --names-only 'readline.*dev.*'
apt-cache search --names-only 'php.*dev.*'
apt-cache search --names-only 'bzip'
apt-cache search --names-only 'bz.*dev.*'
apt-cache search --names-only 'bison.*'apt-cache search --names-only 'libmcrypt.*'
apt-cache search --names-only 'libpqxx.*'
apt-cache search --names-only 'libxslt.*'
apt-cache search --names-only 'pcre.*'
apt-cache search --names-only 'libcurl.*'
apt-cache search --names-only 'libgsasl.*'
apt-cache search --names-only '.*readline.*'
libreadline-dev - GNU readline and history libraries, development filesphp-all-dev - package depending on all supported PHP development packages
php-dev - Files for PHP module development (default)
php7.2-dev - Files for PHP7.2 module development
bzip2 - high-quality block-sorting file compressor - utilities
libbz2-dev - high-quality block-sorting file compressor library - development
bison - YACC-compatible parser generator
libbison-dev - YACC-compatible parser generator - development library
libmcrypt-dev - De-/Encryption Library development files
libmcrypt4 - De-/Encryption Library
libpqxx-4.0v5 - C++ library to connect to PostgreSQL
libpqxx-dev - C++ library to connect to PostgreSQL (development files)
libxslt1-dev - XSLT 1.0 processing library - development kit
libxslt1.1 - XSLT 1.0 processing library - runtime library
libgsasl7 - GNU SASL library
libgsasl7-dev - Development files for the GNU SASL library
libreadline-dev - GNU readline and history libraries, development files
readline-common - GNU readline and history libraries, common files
libpcre2-dev - New Perl Compatible Regular Expression Library - development files
libpcre2-posix0 - New Perl Compatible Regular Expression Library - posix-compatible runtime files
# orlibpcre3 - Old Perl 5 Compatible Regular Expression Library - runtime files
libpcre3-dev - Old Perl 5 Compatible Regular Expression Library - development files
libcurl4 - easy-to-use client-side URL transfer library (OpenSSL flavour)
libcurl4-openssl-dev - development files and documentation for libcurl (OpenSSL flavour)
libreadline-dev readline-commonphp-all-dev
php-dev
php7.2-dev
bzip2
libbz2-dev
bison
libbison-dev
libmcrypt-dev
libmcrypt4
libpqxx-4.0v5
libpqxx-dev
libxslt1-dev
libxslt1.1
libgsasl7
libgsasl7-dev
libreadline-dev
readline-common
libcurl4 libcurl4-openssl-devlibpcre2-dev libpcre2-posix0
sudo apt-get install -y \
libreadline-dev \
readline-common \
php-all-dev \
php-dev \
php7.2-dev \
bzip2 \
libbz2-dev \
bison \
libbison-dev \
libmcrypt-dev \
libmcrypt4 \
libpqxx-4.0v5 \
libpqxx-dev \
libxslt1-dev \
libxslt1.1 \
libgsasl7 \
libgsasl7-dev \
libreadline-dev \
readline-common \
libcurl4 \
libcurl4-openssl-dev \
libpcre2-dev \
libpcre2-posix0
The following additional packages will be installed:
autoconf automake autopoint autotools-dev bzip2-doc comerr-dev debhelper dh-autoreconf dh-strip-nondeterminism gettext gir1.2-harfbuzz-0.0 icu-devtools intltool-debian krb5-multidev
libarchive-cpio-perl libarchive-zip-perl libcom-err2 libfile-stripnondeterminism-perl libglib2.0-0 libglib2.0-bin libglib2.0-dev libglib2.0-dev-bin libgraphite2-dev libgssrpc4
libharfbuzz-dev libharfbuzz-gobject0 libharfbuzz-icu0 libicu-dev libicu-le-hb-dev libicu-le-hb0 libiculx60 libidn11-dev libkadm5clnt-mit11 libkadm5srv-mit11 libkdb5-9 libltdl-dev
libmail-sendmail-perl libntlm0 libntlm0-dev libpcre16-3 libpcre2-16-0 libpcre2-32-0 libpcre2-8-0 libpcre3-dev libpcre32-3 libpcrecpp0v5 libpq-dev libpq5 libsodium23 libssl-dev
libsys-hostname-long-perl libtimedate-perl libtinfo-dev libtool libxml2-dev m4 php-pear php-xml php7.2-cli php7.2-json php7.2-opcache php7.2-readline php7.2-xml pkg-config
pkg-php-tools po-debconf python3-distutils python3-lib2to3 shtool zlib1g-dev
Suggested packages:
autoconf-archive gnu-standards autoconf-doc bison-doc doc-base dh-make dwz gettext-doc libasprintf-dev libgettextpo-dev krb5-doc libcurl4-doc libkrb5-dev libldap2-dev librtmp-dev
libssh2-1-dev libglib2.0-doc libgraphite2-utils krb5-user icu-doc libtool-doc mcrypt postgresql-doc-10 libpqxx4-doc readline-doc libssl-doc gfortran | fortran95-compiler gcj-jdk
m4-doc dh-php libmail-box-perl
The following NEW packages will be installed:
autoconf automake autopoint autotools-dev bison bzip2-doc comerr-dev debhelper dh-autoreconf dh-strip-nondeterminism gettext gir1.2-harfbuzz-0.0 icu-devtools intltool-debian
krb5-multidev libarchive-cpio-perl libarchive-zip-perl libbison-dev libbz2-dev libcurl4-openssl-dev libfile-stripnondeterminism-perl libglib2.0-bin libglib2.0-dev libglib2.0-dev-bin
libgraphite2-dev libgsasl7 libgsasl7-dev libgssrpc4 libharfbuzz-dev libharfbuzz-gobject0 libharfbuzz-icu0 libicu-dev libicu-le-hb-dev libicu-le-hb0 libiculx60 libidn11-dev
libkadm5clnt-mit11 libkadm5srv-mit11 libkdb5-9 libltdl-dev libmail-sendmail-perl libmcrypt-dev libmcrypt4 libntlm0 libntlm0-dev libpcre16-3 libpcre2-16-0 libpcre2-32-0 libpcre2-8-0
libpcre2-dev libpcre2-posix0 libpcre3-dev libpcre32-3 libpcrecpp0v5 libpq-dev libpq5 libpqxx-4.0v5 libpqxx-dev libreadline-dev libsodium23 libssl-dev libsys-hostname-long-perl
libtimedate-perl libtinfo-dev libtool libxml2-dev libxslt1-dev m4 php-all-dev php-dev php-pear php-xml php7.2-cli php7.2-dev php7.2-json php7.2-opcache php7.2-readline php7.2-xml
pkg-config pkg-php-tools po-debconf python3-distutils python3-lib2to3 shtool zlib1g-dev
The following packages will be upgraded:
libcom-err2 libglib2.0-0 libxslt1.1
phpbrew install 7.3
checking for libzip... not found
configure: error: Please reinstall the libzip distribution
libzip-dev - library for reading, creating, and modifying zip archives (development)
libzip4 - library for reading, creating, and modifying zip archives (runtime)
sudo apt-get install -y libzip-dev libzip4
phpbrew install 7.3
Source: github.com
phpbrew install --jobs=8 7.3
===> phpbrew will now build 7.3.14
You haven't enabled any variants. The default variant will be enabled:
[bcmath, bz2, calendar, cli, ctype, dom, fileinfo, filter, ipc, json, mbregex, mbstring, mhash, pcntl, pcre, pdo, pear, phar, posix, readline, sockets, tokenizer, xml, curl, openssl, zip
]
Please run 'phpbrew variants' for more information.
phpbrew list
phpbrew use php-7.3.14
# The extensions installed by phpbrew:bcmath, bz2, calendar, cli, ctype, dom, fileinfo, filter, ipc, json, mbregex, mbstring, mhash, pcntl, pcre, pdo, pear, phar, posix, readline, sockets, tokenizer, xml, curl, openssl, zip# The extensions in my Alpine container, for use with Drupal:${PHP_VERSION}-curl \# Required by Composer and Drupal installer.${PHP_VERSION}-mbstring \# The Drupal installer complains when you don't have opcache enabled.${PHP_VERSION}-opcache \# Required in Drupal core composer.json.${PHP_VERSION}-dom \${PHP_VERSION}-gd \${PHP_VERSION}-json \${PHP_VERSION}-pdo \${PHP_VERSION}-pdo_mysql \${PHP_VERSION}-session \${PHP_VERSION}-simplexml \${PHP_VERSION}-tokenizer \${PHP_VERSION}-xml \
  1. pdo_mysql
  2. session
  3. tokenizer
  4. gd
  5. opcache

#1 PDO MySQL extension

phpbrew ext install pdo_mysql
In file included from /home/wsl/.phpbrew/build/php-7.3.14/ext/pdo_mysql/pdo_mysql.c:30:0:
/home/wsl/.phpbrew/build/php-7.3.14/ext/pdo_mysql/php_pdo_mysql_int.h:25:11: fatal error: ext/mysqlnd/mysqlnd.h: No such file or directory
phpbrew ext install mysqlnd
...
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
apt-cache search --names-only '.*openssl.*'
sudo apt-get install -y openssl
phpbrew ext install mysqlnd
sudo apt-cache search --names-only '.*libssl.*'
sudo apt-get install -y libssl-dev libssl1.1sudo apt list --installed | grep ssl
phpbrew install --jobs=8 7.3 +default +openssl=/usr

# 2 Session

phpbrew ext install session

# 3 Tokenizer

phpbrew ext install tokenizer

#4 Installing GD and dependencies

apt-cache search --names-only '.*libgd.*' | grep -i 'graphic'
sudo apt-get install -y libgd3 libgd-dev
phpbrew ext install gd

# 5 Opcache

phpbrew ext install opcache

About those build warnings

PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'session.so' in Unknown on line 0
Warning: Module 'tokenizer' already loaded in Unknown on line 0
/home/wsl/.phpbrew/php/php-7.3.14/etc/php.ini
php --iniConfiguration File (php.ini) Path: /home/wsl/.phpbrew/php/php-7.3.14/etc
Loaded Configuration File: /home/wsl/.phpbrew/php/php-7.3.14/etc/php.ini
Scan for additional .ini files in: /home/wsl/.phpbrew/php/php-7.3.14/var/db
Additional .ini files parsed: /home/wsl/.phpbrew/php/php-7.3.14/var/db/gd.ini,
/home/wsl/.phpbrew/php/php-7.3.14/var/db/opcache.ini,
/home/wsl/.phpbrew/php/php-7.3.14/var/db/session.ini,
/home/wsl/.phpbrew/php/php-7.3.14/var/db/tokenizer.ini,
/home/wsl/.phpbrew/php/php-7.3.14/var/db/xdebug.ini
/home/wsl/.phpbrew/php/php-7.3.14/var/db/session.ini
/home/wsl/.phpbrew/php/php-7.3.14/var/db/tokenizer.ini

Whew !

--

--

--

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

8 Agile Testing Best Practices That Will Help To Boost Efficiency And Productivity Of Your Team

Kotlin Multiplatform Mobile (KMM) at Granular

Frontend Development and the Perils of Garlic Shrimp

Image-building best practices

When to use CQRS?

An Introduction to Message Queues With RabbitMQ and Python

Life is a journey of twists and turns, peaks and valleys, mountains to climb and oceans to explore.

Meeting & Working with a Docker Captain

Get the Medium app

Callback Insanity

Callback Insanity

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.

More from Medium

Debug Walkthrough: Exploiting SSH MOTD and PHP Deserialization

How to get mac address of client machine in PHP

How To Write A Simple PHP Shell