Skip to content

Instantly share code, notes, and snippets.

@samuelbradshaw
Last active April 20, 2022 01:31
Show Gist options
  • Save samuelbradshaw/83fc01ee91379311477e1ef758f8bbde to your computer and use it in GitHub Desktop.
Save samuelbradshaw/83fc01ee91379311477e1ef758f8bbde to your computer and use it in GitHub Desktop.
Installing PHP on macOS

Installing PHP on macOS

Starting with macOS 12 (Monterey), PHP is no longer bundled with macOS. These instructions allow you to install PHP. The instructions were tested on an Apple Silicon Mac, but the process on an Intel Mac should be similar.

Install Homebrew

Homebrew is a popular package manager that makes it easy to install command line tools. If you don’t yet have Homebrew installed, instructions can be found here: https://brew.sh

Verify that Homebrew is installed:

brew -v

Install PHP

  1. Run the Homebrew install script for PHP:
brew install php
  1. Start the PHP background service:
brew services start php
  1. Verify that PHP is installed and that the service is running:
php -v
brew services list

Verify that PHP is working

  1. Create a sample php file called info.php with the following content:
<?php
phpinfo();
?>
  1. In Terminal, go to the directory where the PHP file is located:
cd /path/to/directory
  1. Run the PHP development server with the current directory as the document root:
php -S localhost:8000 -t .
  1. Open localhost:8000/info.php in your web browser. You should see the PHP info page you created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment