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 http://jamesclarke.net/notes/libxml2 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.
- Download both the files attached and extract.
- Open a terminal into the libxml2-2.9.7 folder
- Run the command
./configure
- If all is well run
make
- If all is well run
sudo make install
- Now open a terminal into the libxslt-1.1.32 folder
- Run the command
./configure
- If all is well run
make
- If all is well run
sudo make install
- 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.
- Run the command
./configure
- If all is well run
make
- 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