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.
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
- Run the Homebrew install script for PHP:
brew install php
- Start the PHP background service:
brew services start php
- Verify that PHP is installed and that the service is running:
php -v
brew services list
- Create a sample php file called info.php with the following content:
<?php
phpinfo();
?>
- In Terminal, go to the directory where the PHP file is located:
cd /path/to/directory
- Run the PHP development server with the current directory as the document root:
php -S localhost:8000 -t .
- Open
localhost:8000/info.php
in your web browser. You should see the PHP info page you created.