Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run my php file from mac terminal

Tags:

Sorry if this is a very novice question - I am a novice - but, I have no clue how to run my php file from the terminal.

I type in the mac terminal something like this: php test.php (where test.php is the file i'm trying to run) Then, I get this: Could not open input file: test.php

I think I'm having this problem because I didn't change the directory (not sure how to do that either).

like image 780
Wenqin Ye Avatar asked Jul 24 '13 02:07

Wenqin Ye


People also ask

Can you run PHP from command line?

However, PHP does allow you to install it and run scripts on your local machine with no web access needed. Running PHP from Windows command line can be especially useful when trying to rapidly develop custom scripts, or to read and modify local files. In the example, we will use a custom PHP iterator.

How do I run a PHP file?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.


1 Answers

In order to change the directory, you must type cd and then the file path name

If you find the file in Finder, and hold the file, and drag it to the mac terminal window, it will place the entire path file....so just type cd, then drag file to get path

  • DO NOT FORGET TO REMOVE THE FILE NAME ON THE END OF THE PATH

and that will take you to the directory of the file..

after that, just type php test.php, and that should work

Hope this helps!

like image 189
user2277872 Avatar answered Oct 25 '22 13:10

user2277872