Current Location: Home> Latest Articles> How to Update PHP Version on macOS | Complete Step-by-Step Guide

How to Update PHP Version on macOS | Complete Step-by-Step Guide

gitbox 2025-06-29

Check the Current PHP Version

Before updating PHP, first check the current version. Open the Terminal and run the following command:

php -v

This command will display the currently installed PHP version. If you find the version outdated, you can proceed with the update steps.

Update PHP Using Homebrew

Homebrew is a powerful package manager that makes it easy to install and update PHP. If Homebrew is not yet installed, you can install it using the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once installed, you can update PHP by running the following command:

brew install php

This command will automatically download and install the latest PHP version.

Switch PHP Versions

If you have multiple PHP versions installed, you can switch to the desired version using the following command:

brew link --overwrite --force [email protected]

Replace the version number with the one you wish to use. This command will set the specified version as the active one on your system.

Configure PHP Environment

After installing and switching PHP versions, you may need to adjust some PHP configurations. PHP configuration files are typically located at:

/usr/local/etc/php/php.ini

Navigate to the relevant directory for your PHP version, open the php.ini file, and make any necessary changes using your preferred text editor.

Restart Services

After modifying PHP configurations, restart the corresponding services to apply the changes. For Apache, use the following command:

sudo apachectl restart

If you're using Nginx, you can restart it with:

brew services restart nginx

Verify PHP Update

Once all the steps are complete, you can run the command again to verify if PHP has been successfully updated:

php -v

If the output displays the PHP version you expect, the update was successful!

Conclusion

Updating the PHP version on macOS is a straightforward and effective process. By using Homebrew, you can easily install the latest PHP version and configure your environment. Keeping PHP up-to-date will not only improve project performance but also ensure a smoother development workflow. We hope this guide helps you successfully update PHP on your macOS system!