Welcome to our complete guide to help you navigate through the installation or upgrade process of PHP 8.3 using Homebrew on macOS. Whether you’re a seasoned developer or just starting, this guide will make your life easier with step-by-step instructions in simple, human-friendly language. PHP 8.3 comes packed with exciting new features like typed class constants, granular exceptions in the DateTime extension, and the new json_validate function. Let’s dive in!
How to install PHP 8.3 with Homebrew
First things first, you need Homebrew installed on your macOS. If you haven’t done that yet, head over to the Homebrew website to get started. Once you have Homebrew set up, you can follow these quick commands to install PHP 8.3:
# Add the PHP and PHP Extension taps maintained by Shivam Mathur
brew tap shivammathur/php
brew tap shivammathur/extensions
# Install PHP 8.3
brew install shivammathur/php/php@8.3
# Make PHP 8.3 the default PHP version on your CLI
brew link --overwrite --force shivammathur/php/php@8.3
# Verify the installation
php -v
That’s it! You’ve just installed PHP 8.3. For those who prefer a more detailed and thorough walkthrough, let’s break down each step below.
Detailed Installation/Upgrade Guide
1. Prerequisites
Before diving into the installation, you’ll need Homebrew installed on your macOS. You can check out the Homebrew documentation if you need assistance. This guide has been tested on macOS Monterey, Ventura, and Sonoma.
2. List Existing PHP Packages
If you’re upgrading from an older PHP version, it’s good practice to list your existing PHP packages. This can help you reinstall the same packages after upgrading.
brew list --full-name | grep -E "php|shivammathur/extensions" > packages.txt
This command will save the list of PHP-related packages you currently have installed to a packages.txt
file, making it easy to reference later.
3. Add the PHP Taps to Homebrew
Shivam Mathur maintains two Homebrew taps, shivammathur/php
and shivammathur/extensions
, which are essential for installing PHP 8.3 and its extensions.
brew tap shivammathur/php
brew tap shivammathur/extensions
4. Install PHP 8.3
With the taps added, you can now install PHP 8.3 with a command:
brew install shivammathur/php/php@8.3
brew link --force --overwrite shivammathur/php/php@8.3
This command installs PHP 8.3 along with several core extensions. While it’s not possible to customize the initial set of extensions without recompiling PHP, you can install additional extensions after the installation.
5. Install Additional PHP Extensions
Need more features? Shivam Mathur’s extensions tap has you covered. You can easily add popular PECL extensions. Here are a few examples:
# Install Xdebug for PHP 8.3
brew install shivammathur/extensions/xdebug@8.3
# Install APCu for PHP 8.3
brew install shivammathur/extensions/apcu@8.3
# Install IMAP for PHP 8.3
brew install shivammathur/extensions/imap@8.3
# Install PCOV for PHP 8.3
brew install shivammathur/extensions/pcov@8.3
# Install Redis for PHP 8.3
brew install shivammathur/extensions/redis@8.3
# Install Swoole for PHP 8.3
brew install shivammathur/extensions/swoole@8.3
# Install YAML for PHP 8.3
brew install shivammathur/extensions/yaml@8.3
For a complete list of available extensions, check out Shivam Mathur’s homebrew-extensions.
6. Web Server Integrations
If you use PHP with a web server, you’ll need to restart or reload your web server to apply the changes.
For Apache:brew services restart httpd
For Nginx:brew services restart nginx
For Caddy:caddy reload
7. Verify Your PHP 8.3 Installation
To make sure everything is set up correctly, use the following command:
php -v
You should see output similar to:
PHP 8.3.0 (cli) (built: ...)
8. Migrate Configuration
Updating to PHP 8.3 from an older version? PHP 8.3 configuration files are located at /opt/homebrew/etc/php/8.3
. It’s best not to copy your old INI files directly to this directory.
cd /opt/homebrew/etc/php/8.3
Instead of copying, manually transfer the necessary INI directives from your old configuration to the new one. This will help you avoid deprecated or incompatible settings. For more information, check out What’s New and Changed in PHP 8.3.
9. Remove Old PHP Versions
If you’re upgrading, it’s a good idea to remove old PHP versions to keep your system clean.
For PHP installed from Brew’s core packages:brew uninstall php@8.2
For PHP installed from Shivam Mathur’s tap:brew uninstall shivammathur/php/php@8.1
By following these detailed steps, you can ensure a smooth transition to PHP 8.3.
What’s New in PHP 8.3?
PHP 8.3 is packed with new features and improvements:
- Typed Class Constants: Learn More
- Granular Exceptions in DateTime extension
- New json_validate Function: Read More
- Various functionality changes and performance improvements
Each of these features aims to make PHP a more powerful and efficient language.
Conclusion
Transitioning to PHP 8.3 on macOS using Homebrew is a straightforward process when broken down into manageable steps. With new features and enhancements, PHP 8.3 is ready to take your development to the next level. Whether you’re installing PHP for the first time or upgrading from an older version, our guide has you covered.
If you have any questions or run into issues, feel free to leave a comment or reach out for support. Your journey to mastering PHP continues, and we’re here to help.
FAQ
How to install different versions of PHP on Mac?
Use Homebrew to install multiple PHP versions: brew install php@7.4, brew install php@8.0, etc. Switch between versions with brew link php@version –force.
Where is PHP in Homebrew?
PHP installed via Homebrew is located in /opt/homebrew/opt/php for Apple Silicon Macs, or /usr/local/opt/php for Intel Macs. Configuration files are in /opt/homebrew/etc/php/version or /usr/local/etc/php/version.