How to run PHP locally on MacOS

OSX comes with php installed :

$ which php # => /usr/bin/php

So you can run your php file. But don’t forget to include your code between <?php ... ?>.

// test.php
<?php
echo("Hello world")
?>

So now you can run in your terminal:

$ php test.php
$ Hello world%

Apache is not needed.

Leave a Comment