Installing PHP 7.2 on arch using Phpbrew

By on

First of all: PHP 7.2 is old and unsupported. I know. But for a certain project I had to test something on PHP 7.2. Since it's no longer in the Arch repositories (and not even the AUR package managed to install) I wanted to use phpbrew.

So I tried the simplest command:

phpbrew install 7.2.34 +default +cgi +gd +pdo +mysql +fpm +mbstring

Which resulted in the following error:

===> Building...
Error: Make failed:
The last 5 lines in the log file:
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~

/usr/include/openssl/rsa.h:289:29: note: expected ‘RSA *’ {aka ‘struct rsa_st *’} but argument is of type ‘const struct rsa_st *’

  289 |                        RSA *rsa, int padding);

      |                        ~~~~~^~~

make: *** [Makefile:734: ext/openssl/openssl.lo] Error 1

Please checkout the build log file for more details:
         tail /home/skerit/.phpbrew/build/php-7.2.34/build.log

Long story short: this PHP version expects to use OpenSSL 1.1, but OpenSSL 3 is found.

Installing OpenSSL 1.1

Even though there is an OpenSSL 1.1 package in the AUR, I couldn't get it to work with phpbrew. Because I didn't feel like actually wasting even more hours on it, I went with another solution by peter279k on Github to manually compile openssl-1.1 in my home folder:

cd $HOME
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar xzf $HOME/openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
./Configure --prefix=$HOME/openssl-1.1.1i/bin -fPIC -shared linux-x86_64
make -j 8 
make install

Installing with PHPBrew again

On Ubuntu it's apparently enough to compile the new build like this:

export PKG_CONFIG_PATH=$HOME/openssl-1.1.1i/bin/lib/pkgconfig && phpbrew install 7.2.34 +default +cgi +gd +pdo +mysql +fpm +mbstring

I can't confirm, because I'm using Arch Linux. Luckily, another user elvisoliveira figured out the way to make it work on Arch:

cd $HOME/openssl-1.1.1i/bin
export LDFLAGS="-L$(pwd)/lib"
export CPPFLAGS="-I$(pwd)/include"
phpbrew install 7.2.34 +default +cgi +gd +pdo +mysql +fpm +mbstring

And now it compiled & installed without a problem. Finally!

Configuring a starting the php-fpm server

I like to move the socket file where the php-fpm server listens for connections. This file will be here:

nano $HOME/.phpbrew/php/php-7.2.34/etc/php-fpm.d/www.conf

The default socket file will be something like:

listen = /home/skerit/.phpbrew/php/php-7.2.34/var/run/php-fpm.sock

I like to change that to another directory I made that I can more easily let nginx access, for example:

listen = /run/phpbrew/fpm72.sock

To actually start the fpm server, execute the following commands:

phpbrew use php-7.2.34
phpbrew fpm start

Fyi: phpbrew use will change the active php version in your current terminal session. Using phpbrew switch will make it the new default version instead.

Getting gd to work

Even though compilation worked fine, and the fpm server is working, I kept getting this error:

Call to undefined function imagecreatefromstring()

This is a function that uses gd, and even though I had installed the gd variant, it wasn't loaded yet.

This isn't hard to fix either. Just open this file:

nano $HOME/.phpbrew/php/php-7.2.34/etc/php.ini

And in the Dynamic Extensions section, add this:

extension=gd

You might notice there is a commented out line ;extension=gd2 (lines starting with ; are comments in this file)

GD2 is a newer version of the GD library, but for some reason this variant we installed is still known as just gd.

Comments

Name
Email
Website
Body
submit error done Busy
Jelle De Loecker