Skip to content

How to run my php file from mac terminal?

To run a PHP file from the Mac terminal, you will need to have PHP installed on your system. You can verify the installation by running php -v in the terminal. Once confirmed, navigate to the directory where your PHP file is located in the terminal, and type php followed by the name of your file, like this:

console
php myfile.php

If your PHP file is designed to output something, you should see the result directly in the terminal via the command line interface (CLI).

Another way is to use the built-in server of PHP by running the command:

console
php -S localhost:8000

This will start a server on localhost on port 8000. Then you can access the file by going to http://localhost:8000/myfile.php on your browser.

Dual-run preview — compare with live Symfony routes.