The PHP versions for macOS is maintained in third party repository that can be add to system with brew tap. It also allows you to install and use multiple PHP versions on a single macOS system. This tutorial will help you to install PHP on macOS.


Before starting the installation of PHP using this tutorial you must have the following prerequisites

Terminal: You must have Mac Terminal access and little knowledge about working with the terminal application. Ao login to your Mac system and open terminal Homebrew: Homebrew is a popular package manager for the Mac operating systems. It is useful for installing most open-source software like Node. You can install Homebrew with the following command./bin/bash -c “$(curl -fsSL"


How to Install PHP on macOS

The latest version of macOS Sierra ships with PHP 5.6 and OSX 10.11 El Capitan with PHP 5.5, and OSX 10.8 Mountain Lion ships with PHP version 5.3. The latest version of PHP 8.1 is available to install. The steps below help you install PHP 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, or 5.6 on the macOS system.

Configure PHP with Apache

Edit the Apache configuration file and a text editor: Add the following snippet to the file: You can also change the directory index:

Save the file and close it. Now restart the Apache service to apply changes: Now create a phpinfo() function file and access in the browser.

Upgrade PHP version

You can upgrade your PHP version to the latest patch release using the brew upgrade command. For example, to upgrade PHP 8.1:

Switch Active PHP Version

If you have installed multiple PHP versions on your system, you can switch to a new version anytime. For example, to switch to PHP 7.4: Make sure you already have installed the PHP 7.4 version on your system.


This guide helped you to install PHP on the macOS system. You can install multiple PHP versions on a single system and switch between them anytime.

How to Install PHP  8 1  7 4 or 5 6  on MacOS   TecAdmin - 17