How to run .php server on Mac using Terminal without installing anything

how to run php file on MacOS terminal without installing virtual server

Run php file on Mac OS using Terminal without installing virtual server

When you go around many search result for running php file on Mac, you will find out so many results for this topic. However, most of them are so complex and even irrelevant to what you you want. In this post, I would like to share very clear and easy steps to run php files using only Terminal without installing anything.

Step 1: Open Terminal window and put the folder which containing the php file into the terminal.

Note: If you are in an other branch on Terminal, you can exit this by typing in the terminal: cd ENTER

Now, in terminal, type cd then drag the folder and drop it into the terminal right after cd , then ENTER

Step 2: Request Terminal to run php

Type php -S ENTER

In my case, the file .php is inside contacts folder, so the result is like this:

PHP 7.1.16 Development Server started at Thu Dec 27 13:54:32 2018
Listening on
Document root is /Users/myComputer/projects/website/contacts
Press Ctrl-C to quit.

Step 3: Display php file on browser

Open a browser, type localhost:8080 ENTER in the http box. Below is the result displaying my php file on browser.

php file displays on browser through terminal command

Note: in order to display the php file on browser, you need to have a file with format .php already in the folder.

Let’s work on php file as normal.


Happy coding!


About: Thamtran

One thought on “How to run .php server on Mac using Terminal without installing anything”

Leave a Reply

Your email address will not be published. Required fields are marked *