Upgrading or Downgrading PHP on OS X Server

Update 9/29/17: macOS Server 5.4 ships with php 7.0, so this could get you to version 7.1 or 7.2 and also be considered a downgrade guide as well if you’re not ready for the version 7 series.

I have written twice about Apple moving their Server product away from industry standards or outright removing features. The first was “OS X Server – How to Ween Customers Off Your Own Platform” and the second was when I found they discontinued support for NTP as a service.

Well, here we are. Again. This time it concerns PHP, cURL, OpenSSH, and Apple going in their own direction.

This tale starts with me moving from Pebble to WordPress. Once I got a feel for how WordPress works, I really liked it. Then I discovered the plugins available for it and how you could easily link your posts with social media. “Great!”, I thought. “This will be cake!” and immediately began to experiment. I installed a plugin that talks to FaceBook and during the setup I got an error that I traced back to cURL not speaking securely to the FaceBook API. A little research led me to this when run from a terminal:

Which led to some reading about Secure Transport which is Apple’s implementation of TLS (formally SSL). They are now using it on OS X starting with Yosemite instead of OpenSSL because they also use it on iOS which flat-out doesn’t have an option for OpenSSL. Okay, I guess that makes sense, but in an effect to save users from themselves, it doesn’t allow outgoing encrypted web communications. Some says it’s broken and needs to be fixed. I say, “tomayto, tomahto.” We wouldn’t even be here if Apple just used something standard.

Time to replace Apple’s PHP and cURL with a version that goes back to standards.

This time to install something that Apple didn’t include, I decided to use Homebrew. That could be a whole blog entry in and of itself, and maybe it will be, but the short version is that most are migrating to it instead of MacPorts.

First thing to do is head on over to the Homebrew Homepage and get it installed if you haven’t. It’s a pretty straightforward Terminal command to do so:

Next, do each of these from the command line:

In order, what these do for Homebrew:

dupes – informs Homebrew about available packages for OS X that are already included with OS X, however those installed by Homebrew will be newer and/or contain bug fixes and will be installed in a separate directory so as not to conflict with Apple’s included versions.

versions – simply gives you the ability to install multiple versions of the same package e.g. php 55, 56 or 71.

php – well, this is pretty obvious, our php repository.

Let’s get going with our first one, cURL with OpenSSL, instead of that nasty Secure Transport:

As mentioned above, because this is a dupe of something that OS X provides, it will not replace Apple’s version, it installs it in a separate directory that you have to implicitly path if you want to use it. That’s okay, because we’ll be telling PHP to do just that. Note below when we now tell Homebrew to install our PHP it is “–with-homebrew-curl

Here, you have a choice. I’ve tried it with PHP5.5, 5.6, and 7.1. Instructions are the same for both 5.5 and 5.6 and different for 7.1.




This will take awhile to install PHP with all the dependancies needed.

Finally, we need to tell Server to use our version of PHP rather than Apple’s. Using the editor of your choice, edit /Library/Server/Web/Config/apache2/httpd_server_app.conf

Towards the end of the LoadModules section, change things around so they look like this depending on your php version choice:

There is a trick I did here. Since this is a configuration file managed by Apple’s Server.app, things in it will get overwritten/changed because, as we all have learned, Apple knows what is best for us. Well, one of those things is their LoadModule php5_module libexec/apache2/libphp5.so. If you try to comment it out, they’ll just remove your comment the next time Server.app is loaded or you restart the server.

By moving their line to the end and inserting our Homebrew PHP LoadModule before it, ours will be used first so when Apache tries to load Apple’s version it will fail with a harmless “module php5 is already loaded, skipping” in your log file.

So, that’s it. For me, this was simply a point A to point B exercise to get the minimum I needed for PHP to do what I wanted in WordPress. I could maybe have gone with PHP 7.2 instead of 7.1, for example, but I wanted to keep things as close to baseline with Apple as possible in case there were some other hidden dependency “gotchas” waiting for me. There are many other configuration options in the install of PHP that can be used, and in fact might be needed if you’re following this for anything but my intended use. This should provide you some tips to get started if so.

4 Replies to “Upgrading or Downgrading PHP on OS X Server”

  1. With server version 5.6 a downgrading to php version 56 does not seem to be working anymore and results in a “Websites are deactivated” message on a page request. In contrast homebrewed php 7.1 version works as expected.

    Here is the lines from my http_server_app.conf when trying to load php 5.6:
    LoadModule php5_module /usr/local/Cellar/php56/5.6.33_9/libexec/apache2/libphp5.so
    #LoadModule php7_module /usr/local/Cellar/php71/7.1.14_25/libexec/apache2/libphp7.so
    LoadModule php7_module libexec/apache2/libphp7.so

    Has anyone similar issues🤔? Thanks

  2. Never mind, I just gave it another try and succeeded. Moreover I’m even unable to reproduce my above issue. Thanks anyways

Leave a Reply

Your email address will not be published. Required fields are marked *