You are here
Home > How to > Upgrading PHP 5.6 on macOS Sierra running Server 5.2

Upgrading PHP 5.6 on macOS Sierra running Server 5.2

This has been a long struggle, but here it is – the guide for upgrading PHP 5.6 on macOS Sierra running Server 5.2.

What started it all was that I wanted to switch from Google Analytics to Piwik, a self hosted web analytics software. The challenge was that the PHP configuration in MacOS Server 5.2 does not include FreeType in the included GD library – this is a requirement for Piwik to work.

So looked at the options for including FreeType, trying to force PHP to load another version of GD than the one it comes compiled with – this turned out to be a dead end.

Another solution was to use the PHP 5.6 version that is installed with MacPorts, however when looking at the libraries this comes compiled with, compared to the one compiled into MacOS version, there’s a few modules missing, hence I feared that I may break something – I wanted a PHP version as close to the one that’s distributed with macOS Sierra.

So then it was up the steep learning curve, trying to figure out how to compile PHP under OS X.

Here follows a step-by-step guide of how I made it work.

As of writing this, the server were running with:

  • macOS 10.12.3 (Build 16D32)
  • Server 5.2 (Build 16S1195)
  • PHP v5.6.28

Before we begin, a huge thanks to the Web, for a lot of usefull guides.

1. Download and extract PHP v5.6.28

Create a /usr/local/src directory if it doesn’t already exist

cd /usr/local
sudo mkdir src
sudo chown <adminID> src 
sudo chgrp admin src
chmod 750 src

Change to the source directory and unpack PHP source code

cd src
tar -xvjf ~/Downloads/php-5.6.28.tar.bz2

2. Install the following required MacPorts

Note that if OpenSSL is installed, this will have to be uninstalled before LibreSSL can be installed – including all depending packages. Only do this in case, you, like me, wanted to switch to LibreSSL. The rest of the guide will be the same if you use OpenSSL.

  • apr
  • apr-util
  • libressl
  • postgresql95
  • freetype +universal
  • jpeg +universal
  • libpng +universal

3. Create dynamic links for apr files

With the dependency of apxs2, comes the requirement for PHP to be able to locate the two files “apr-1-config” and “apu-1-config”.

The only way I could get this to work, where to create a symling between the MacPorts install directory for apr and apr-util, using the commands below.

sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /opt/local/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /opt/local/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/

4. Create dynamic links for LibreSSL required files

Similar issue for LibreSSL as for apr above.
If you use OpenSSL you will need to execute these command as well.

sudo mkdir -p /usr/local/include/
sudo ln -s /opt/local/include/openssl/ /usr/local/include/

5. Create dynamic links for PostgreSQL

sudo ln -s /opt/local/lib/postgresql95/bin/pg_config /opt/local/bin/

6. Run .configure script for PHP56

This is the configure command I ended up using.

./configure \
'--with-iconv=/opt/local' \
'--prefix=/opt/local' \
'--with-apxs2=/usr/sbin/apxs' \
'--sysconfdir=/private/etc' \
'--enable-cli' \
'--with-config-file-path=/etc' \
'--with-openssl=yes' \
'--with-kerberos=yes' \
'--with-zlib=yes' \
'--enable-bcmath' \
'--with-bz2=yes' \
'--enable-calendar' \
'--disable-cgi' \
'--with-curl=yes' \
'--enable-dba' \
'--with-ndbm=yes' \
'--enable-exif' \
'--enable-fpm' \
'--enable-ftp' \
'--with-gd' \
'--with-png-dir=/opt/local' \
'--with-jpeg-dir=/opt/local' \
'--enable-gd-native-ttf' \
'--with-freetype-dir=/opt/local' \
'--with-icu-dir=/opt/local' \
'--with-ldap=yes' \
'--with-ldap-sasl=yes' \
'--with-libedit=yes' \
'--enable-mbstring' \
'--enable-mbregex' \
'--with-mysql=mysqlnd' \
'--with-mysqli=mysqlnd' \
'--with-pdo-pgsql=/opt/local' \
'--with-pgsql=/opt/local' \
'--without-pear' \
'--with-pear=no' \
'--with-pdo-mysql=mysqlnd' \
'--with-mysql-sock=/var/mysql/mysql.sock' \
'--with-readline=yes' \
'--enable-shmop' \
'--with-snmp=yes' \
'--enable-soap' \
'--enable-sockets' \
'--enable-sysvmsg' \
'--enable-sysvsem' \
'--enable-sysvshm' \
'--with-tidy=no' \
'--enable-wddx' \
'--with-xmlrpc' \
'--with-xsl=yes' \
'--enable-zip' \
'--with-pcre-regex=yes' \
'--with-iconv-dir=shared,/opt/local'

7. Edit “Makefile”

Build failed, claiming wrong version of ICONV were being used, searching the web for a solution, checking the installed versions. Apparently this had to do with loading the apx module, at least build succeeded if this was disabled.

Finally found a solution here PHP.Net – Bug #43189 Fails to link iconv where a user had the below solution to the problem.

Add the following line after CONFIGURE_OPTIONS:

EXTRA_CFLAGS = /opt/local/lib/libiconv.a

Then locate the line in Makefile starting with “INSTALL_IT”, and change it as follows (append “/opt/local” two places to the folders where libphp5.so will be installed):

INSTALL_IT = $(mkinstalldirs) '$(INSTALL_ROOT)/opt/local/usr/libexec/apache2' && $(mkinstalldirs) '$(INSTALL_ROOT)/private/etc/apache2' && /usr/sbin/apxs -S LIBEXECDIR='$(INSTALL_ROOT)/opt/local/usr/libexec/apache2' -S SYSCONFDIR='$(INSTALL_ROOT)/private/etc/apache2' -i -a -n php5 libs/libphp5.so

8. Run “make”

Execute the “make” command and wait for PHP to compile.

You may see a lot of warnings, and it may take quite a while to complete.

Once completed without errors, you should be ready to install the new version of PHP 5.6

9. Install the newly compiled PHP

Execute the following command: sudo make install

This will install PHP 5.6 into the /opt/local folder.

10. Edit httpd_server_app.conf

We are almost there, just need to tell the Apache server to use our new PHP library instead of the original one that came with macOS

vi /Library/Server/Web/Config/apache2/httpd_server_app.conf

Remove the line:
LoadModule php5_module libexec/apache2/libphp5.so
And add:
LoadModule php5_module /opt/local/usr/libexec/apache2/libphp5.so

11. Edit PHP.ini

Since I could not make Tidy work when I compiled, I have to load this via PHP.ini.

Install PHP56-tidy via MacPorts.

Then add the following line to /etc/PHP.ini

extension=/opt/local/lib/php56/extensions/no-debug-non-zts-20131226/tidy.so

12. Restart WebService

We are now ready to apply the changes to the WebService in macOS Server.

So restart the “Websites” module in the Server application,

Check the logs to see all is working, and then run a test.php page to verify that PHP is configured as intended.

Similar Articles

Leave a Reply

Top