How To Upgrade PHP On Your Mac

Upgrading PHP on your MacBook can be a real pain. There are numerous tutorials about installing it via homebrew, MacPorts, composer or via some other automated installers. But nothing worked for me. Time to get the hands dirty and do it for once and all.

Getting hands dirty essentially translates into downloading and compiling PHP from source. But it’s not a piece of cake unless you know what you are getting into. Compiling PHP required libxml2 and libxslt. Just follow this link and download the sources. As of this date, the file/versions I got was libxml2-2.9.7.tar and libxslt-1.1.32.tar.gz.

  1. Download both the files attached and extract.
  2. Open a terminal into the libxml2-2.9.7 folder
  3. Run the command ./configure
  4. If all is well run make
  5. If all is well run sudo make install
  6. Now open a terminal into the libxslt-1.1.32 folder
  7. Run the command ./configure
  8. If all is well run make
  9. If all is well run sudo make install
  10. Finally open a terminal into the php-7.2.0 folder — that’s the latest php version available as of the date of this article.
  11. Run the command ./configure
  12. If all is well run make
  13. If all is well run sudo make install

Now if all went well, you can run which php in the terminal and you’ll see something like:
/usr/local/bin/php and if you run /usr/local/bin/php -v you’ll see

PHP 7.2.0 (cli) (built: Dec 16 2017 15:24:18) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
Divi WordPress Theme