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:
Now, in terminal, type
cd then drag the folder and drop it into the terminal right after
cd , then
Step 2: Request Terminal to run php
php -S 127.0.0.1:8080 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 http://127.0.0.1:8080
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.
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.