More Than Just Web Design | INTERNET ENGINEERING | APPLICATION | DESIGN

Compiing PHP 5.6.40 on Ubuntu 18.04

Posted: 06/07/19

Compiling PHP 5.6.40 on Ubuntu 18.04 isn't as straight forward as 16.04. In particular there are issues with CURL and OpenSSL

CURL libraries are not found

The fix here is NOT to symbolic link the /usr/include/x86_64-linux-gnu/curl  folder to /usr/include/curl. Doing that will make it compile for sure, but when you try and actually use the curl_exec function, PHP will segfault.

The solution that worked for me was to grab a copy of the curl source, and compile that and install into /opt/usr/local. I went with a version that was a similar age to PHP 5.6. Later versions might work too. YMMV.

./configure --with-ssl=/opt/usr/local/ --prefix=/opt/usr/local

Once that's done, use the PHP configure option:

--with-curl=/opt/usr/local

OpenSSL causes compile errors

The issue here appears to be that the 1.1.1 release of OpenSSL is incompatible with the PHP 5.6.40 source code. The solution is to build an earlier version and compile against that.

cd /usr/src
wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
tar xfz openssl-1.0.2s.tar.gz
# Install in to  /opt/usr/local/openssl so it does not conflict with anything else
# Compile it as dynamic library
./config -fPIC shared --prefix=/opt/usr/local --openssldir=/opt/usr/local/openssl
make
make test
make install

Now we export the configuration for the PHP configure script to pick up:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Now we build PHP:

cd /usr/src/php-5.6.40
 
./configure \
--with-openssl=/opt/usr/local \
--with-curl=/opt/usr/local \
--prefix=/opt/php/5.6 \
--sysconfdir=/etc/php/5.6 \
--with-fpm-systemd \
--with-config-file-path=/etc/php/5.6 \
--with-config-file-scan-dir=/etc/php/5.6/php.d \
--disable-ipv6 \
--with-jpeg-dir=/usr/include \
--with-mysql \
--with-mysqli \
--enable-fpm \
--with-gd \
--enable-bcmath \
--enable-calendar \
--enable-dba \
--with-enchant \
--with-gettext \
--enable-intl \
--enable-mbstring \
--with-mcrypt \
--with-pcre-regex \
--with-pspell \
--with-readline \
--with-pdo-mysql \
--enable-exif \
--enable-ftp \
--with-mhash \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--enable-zip \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-bz2 \
--with-zlib \
--enable-gd-native-ttf \
--with-xpm-dir=/usr/include/X11 \
--with-freetype-dir=/usr/include/freetype2
 
make
make test
make install

Depending on your enviroment, you may need to add:

openssl.capath=/etc/ssl/certs

to your php.ini so that SSL doesn't throw a hissy fit over certificates it cannot validate.