installphp.info


← Back to home page

Install PHP 7.2 on macOS 12

Warning! This PHP version is end-of-life!

PHP 7.2 reached end of life on 30 Nov 2020 and is no longer being updated. It's strongly recommended to upgrade to the latest version as soon as possible. You can read the official PHP migration guide here.

Installing PHP 7.2 on macOS 12

Prerequisites

  • macOS 12 (Monterey) installed
  • Command Line Tools for Xcode installed
  • Homebrew package manager installed

Installation

  1. Open Terminal
  2. Run the following command to tap the necessary Homebrew repository:
    brew tap shivammathur/php
  3. Install PHP 7.2 using Homebrew:
    brew install shivammathur/php/[email protected]
  4. Link PHP 7.2 to make it the default version:
    brew link [email protected] --force

Verification

  1. Open a new Terminal window or run:
    source ~/.zshrc
  2. Verify the PHP version by running:
    php -v
  3. You should see output similar to:
    PHP 7.2.34 (cli) (built: Apr 16 2021 14:29:29) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies