Introduction: In this tutorial, we’ll walk through the steps to install PHP 8.3 on your macOS using Homebrew. This guide is particularly useful for developers who need to upgrade their PHP version for testing or development purposes.
Requirements:
- macOS (Big Sur, Catalina, Monterey, or later)
- Homebrew installed on your macOS
Step 1: Update Homebrew First, ensure that your Homebrew is up-to-date. Open your terminal and run:
brew update
Step 2: Install PHP 8.3 You have two options to install PHP 8.3. You can either use the built-in PHP recipe or use the shivammathur/homebrew-php
tap. The latter is recommended as it allows easy installation and switching between different PHP versions.
- Option 1: Normal Upgrade
brew upgrade php
- Option 2: Using
shivammathur/homebrew-php
brew tap shivammathur/php brew install shivammathur/php/php@8.3
Step 3: Switching PHP Versions To switch between installed PHP versions, use the following command:
brew link --overwrite --force php@8.3
Step 4: Verify Installation After installation, verify that PHP 8.3 is correctly installed:
php -v
The output should show PHP 8.3.x.
Step 5: Restart Web Server Finally, restart your web server to apply the changes. This could be Nginx or Apache, depending on your setup:
- For Nginx:
sudo nginx -s reload
- For Apache:
sudo apachectl restart
Conclusion: You have successfully installed PHP 8.3 on your macOS using Homebrew. This setup is essential for developers who need to work with the latest PHP features or test their applications on different PHP versions.