How to install PHP on Mac

PHP is installed on latest Mac by default as of 2021.

If your Mac doesn’t have PHP, it can be installed using homebrew. Below is the command to install PHP

brew install php

To run php service, open your terminal and go to folder where your php files are saved. If your files are in Documents/website, on the Terminal type this:

cd Documents/website

Let’s write a simple php code called phpinfo.php

nano phpinfo.php

Copy and paste this code:


To save, hit control + o. To exit, control + x

To run php, paste this command:

php -S

Open open Safari and type in the address bar:

You should see the details of your php.

To stop PHP, hit control + c

Leave a Comment

Your email address will not be published.