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
cd Documents/website

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

nano phpinfo.php

Copy and paste this code:

<?php
phpinfo(); 
?>

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

To run php, paste this command:

php -S 127.0.0.1:8080

Open open Safari and type in the address bar: 127.0.0.1:8080/phpinfo.php

You should see the details of your php.

To stop PHP, hit control + c

Leave a Comment

Your email address will not be published.