Installing PHP 7.2 using Homebrew on OSX using OpenSSL and not Apple’s Secure Transport for PHP’s curl module

Dossy Shiobara
This Old Code
Published in
3 min readJun 2, 2018

There’s a few very good reasons why we may want to build PHP’s curl module using OpenSSL and not Apple’s Secure Transport, such as needing to use PEM format client certificates or wanting to use HTTP/2, for example.

Up until March 2018, this was pretty straightforward to do: you would brew install curl --with-openssl and brew install php72 --with-homebrew-curl and that was it. Slightly inconvenient, but easy. 👍

In their quest to “improve” things by rendering inconvenient but easy things into the downright impossible, the Homebrew maintainers moved the PHP formula from the homebrew-php tap to the homebrew-core tap.

“Sounds harmless,” you might think? Sure, except they didn’t simply move the formula as-is. They changed it in significant ways, including removing the ability to control how PHP’s modules are built. 😡 This means you no longer have the ability to control whether PHP’s curl module is built against the system-provided libcurl library which uses Apple’s Secure Transport, or Homebrew’s libcurl library built against OpenSSL, depending on your preference or needs.

This effectively prevented me from being able to upgrade to a newer PHP using Homebrew’s PHP formula. 😢

Checking StackOverflow, I’m apparently not alone. Since I had a personal need to get PHP 7 installed using this new version of the Homebrew PHP formula on my dev environment, I needed to solve this problem for myself.

Good news: I have a working solution. Let me tell you the story of my people …

I’ve modified the php.rb formula to build PHP against the Homebrew-installed libcurl which you’ll still need to install with brew install curl --with-openssl after installing Homebrew’s OpenSSL with brew install openssl.

To apply it, do this:

$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
$ curl -s https://github.com/dossy/homebrew-core/commit/b75fe286f79e2b89548c5ed1bbe1958313c5c103.patch | patch -p1

Depending on what changes the Homebrew folks make to the php.rb formula between now and when you go to apply this change, it may or may not apply cleanly. I may update the patch periodically, if my change doesn’t make it into the upstream official repository.

Updated 2018–11–07: I’ve created an updated patch against Homebrew’s current php.rb which is for PHP 7.2.11. Use this instead:

$ curl -s https://github.com/dossy/homebrew-core/commit/d0681b61.patch | patch -p1

Once you’ve applied the patch, you’ll need to force an install from source rather than using the precompiled “bottled” binary:

$ brew install php --build-from-source

Depending on your system, this could take a while. But, it should work. When it’s done, you can confirm whether it’s using the correct libcurl and openssl with this command:

$ /usr/local/bin/php -r "var_dump(phpversion(), curl_version()['ssl_version']);"
string(5) "7.2.6"
string(14) "OpenSSL/1.0.2o"

If it didn’t work, instead of OpenSSL/X.Y.Zn you’ll see SecureTransport or LibreSSL. If that happens, something went wrong. Crying at this point wouldn’t be inappropriate nor a terrible idea. Once you’ve regained your composure, double-check your work and if you still can’t get it to work, let me know and maybe I can help you.

For those of you who experienced success, congratulations! I hope this was helpful and saves you a bunch of time and aggravation. I know I sure would have appreciated it …

--

--

Dossy Shiobara
This Old Code

Living la vida startup, doing professional services consulting, and trying to support my wife and two daughters. Free time? What's that ...