How to Install/Upgrade PHP 8.3 on MacOS with Homebrew
With a handful of new features such as typed class constants, granular Exceptions in the DateTime extension, the new json_validate function, functionality changes and improvements, and deprecations, PHP 8.3 is 2023’s major update to PHP. This article explains how to install or upgrade to PHP 8.3 on macOS using Homebrew.
Shivam Mathur maintains two Brew taps, shivammathur/php and shivammathur/extensions that contain precompiled PHP 8.3 packages (bottles) which are kept up to date, making it convenient to install PHP 8.3 and several PHP core and PECL extensions using Homebrew.In the macOS terminal, run the following commands to quickly install PHP 8.3 using Homebrew. Homebrew must be installed first.For detailed steps, see jump to the Detailed Installation/Upgrade guide.
Prerequisites
Make sure to have Homebrew installed. This was tested on macOS macOS Monterey, Ventura, and Sonoma.Installing the PHP 8.3 as shown in the rest of the article requires Homebrew and the two Homebrew taps maintained by Shivam Mathur.
List and keep note of existing PHP packages
When upgrading an existing PHP version, the following command lists all Brew packages, filters them for PHP-related words, and saves them to a packages.txt file. This file can then come in handy later to install the same set of PHP packages for PHP 8.3.This step is not necessary when installing PHP on a new system.
Migrate Configuration
This step only applies when updating to PHP 8.3 from an older PHP version
The configuration files for the PHP 8.3 are located at /opt/homebrew/etc/php/8.3. Existing PHP installations should also be in the /opt/homebrew/etc/php directory.Do not copy existing PHP INI files to /opt/homebrew/etc/php/8.3. While it may work when upgrading from PHP 8.2 or a recent version, manually copying the INI directives is recommended.See What’s new and changed in PHP 8.3 to see the deprecated INI directives and the new INI directive added in PHP 8.3.