As noted in my posts on installing Apache, PHP and MySQL on Mac OS X, Mac OS X comes pre-installed with Apache and PHP. Unfortunately, often the PHP version pre-installed with Mac OS X is outdated:
- Mac OS 10.11 (El Capitan) pre-installed with PHP 5.5
- Mac OS 10.12 (Sierra) pre-installed with PHP 5.6
- Mac OS 10.14 (Mojave) pre-installed with PHP 7.1
Many of these PHP versions are already end of life. In fact, macOS Mojave was the first time the pre-installed version was recent - although still not the latest PHP version.
PHP OSX is a package installer for PHP versions 5.3 to 7.3 (current). It’s available for Mac OS 10.6+ (Snow Leopard to Mojave). While installing PHP OSX is just a few steps, I’ll walk you through each of them.
First, choose the version of PHP you want to install. In this example, I’ll install PHP 7.2 as that is the latest stable version of PHP. However, if you want to install PHP 7.1 that is available as well.
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.2
If you’re not comfortable executing scripts from the Internet, you can do the install by hand.
Provided you are using the pre-installed version of Apache, PHP OSX will add the
/etc/apache2/other/+php-osx.conf configuration file which will automatically be loaded by Apache.
If you had previously enabled PHP (as I did), you’ll need to comment out the following line in
LoadModule php7_module /usr/local/php5/libphp7.so
If you are running an older version of Mac OS X, the line may be:
LoadModule php5_module /usr/local/php5/libphp5.so
Although Apache will now run the new version of PHP, the command line will not. In order for the command line to use the new version of PHP you will need to update your
If you don’t want to run the command above every time you open a new terminal, you can update the
PATH in your
Finally, you will want to update some of the PHP configuration values. PHP OSX installs a PHP INI file for you to change. To edit this file, run:
sudo vi /usr/local/php5/php.d/99-liip-developer.ini
If you kept all of your local PHP configuration within a single INI file (as I did), you can simply append it to the PHP OSX file with:
sudo cat /Library/Server/Web/Config/php/local.ini >> /usr/local/php5/php.d/99-liip-developer.ini
Now you’ll just need to review your PHP code to ensure it’s compatible with your newly installed PHP version. And for that, I recommend PHP Shift.
comments powered by Disqus