Demonstrating a series of simple steps over the Mac's Terminal CLI, to install PHP 8.x on macOS Big Sur.
published on 24 Feb 2021 in Development on macOS PHP Web DevelopmentScroll to the bottom for instructions on the latest version of macOS...
In this tutorial, we'll install the latest version of PHP using Homebrew on macOS Big Sur, also known as macOS 11. This PHP installation features a rich set of extensions and libraries, including those required by version 4 of the CodeIgniter framework.
In the previous tutorial, we've already installed Homebrew on a fresh copy of macOS Big Sur.
Now let's open Mac's Terminal app, and simply type:
brew install php
in the command prompt, and then hit the return key. In this process, your user account needs to have administrative privileges.
This installation may typically take a while, although in this video we fast-forwarded some parts for the sake of brevity. Depending on your system and Internet bandwidth, it can take up to an hour. Therefore be patient, and do not interrupt the installation to avoid polluting your system library directories with intermediate pre-mature installation files.
Homebrew prints some instructions for additional steps to be taken which would be needed to link this very PHP installation to the Apache web server that comes bundled with macOS - though we won't be using it in our demos. In other demos on this blog (and our YouTube channel), we will be testing the web applications created with CodeIgniter Wizard using the built-in web server functionality of the CodeIgniter framework making use of the PHP libraries we are installing in this demo now. Therefore in this tutorial, I will not go along those additional steps instructed by Homebrew. However you can easily save the entire Terminal output to a log file in text format, just in case you need to refer to those instructions later, in order to properly set up a complete web development environment manually by yourself.
Now that our PHP installation is complete, in another tutorial, we'll be demonstrating how to run a web application created with CodeIgniter Wizard on this configuration - so be sure to stay tuned...
What about macOS Monterey, Ventura and later macOS versions?
As of macOS 12 Monterey, Apple completely removed built-in PHP which shipped out-of-the-box with macOS. Therefore the procedure for installing PHP on macOS Monterey using Homebrew has slightly changed.
The below web pages we found on the Internet feature clean, written, step-by-step procedures to explain how to install PHP on newer versions of macOS.
- Add and install PHP to macOS Monterey 12 with Homebrew @ WP Beaches (most brief)
- How to install PHP latest version on MacOS via Homebrew? @ Crunchify (detailed but clear text and screenshots)
- macOS 12.0 Monterey Apache Setup with Multiple PHP Versions @ Grav (most detailed with instructions on how to setup Xdebug as well)
Archibald
Do the instructions here apply for Catalina as well?