如何从 mac 终端运行我的 php 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17824372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run my php file from mac terminal
提问by Wenqin Ye
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.
对不起,如果这是一个非常新手的问题 - 我是一个新手 - 但是,我不知道如何从终端运行我的 php 文件。
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
我在 mac 终端中输入如下内容:php test.php(其中 test.php 是我要运行的文件)然后,我得到这个:无法打开输入文件:test.php
I think I'm having this problem because I didn't change the directory (not sure how to do that either).
我想我遇到了这个问题,因为我没有更改目录(也不知道该怎么做)。
回答by user2277872
In order to change the directory, you must type cd and then the file path name
为了改变目录,你必须输入 cd 然后输入文件路径名
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
如果在 Finder 中找到该文件,并按住该文件,然后将其拖到 mac 终端窗口,它将放置整个路径文件....所以只需键入 cd,然后拖动文件即可获得路径
- 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
之后,只需键入php test.php
,就可以了
Hope this helps!
希望这可以帮助!
回答by MikTek99
Start a terminal window. at the prompt enter 'emacs hi.php' in the emacs editor enter a line that reads print "hi world" enter cntl x-s to save your file then enter cntl-z to exit to the terminal window then type php hi.php you should see "hi world" displayed in the terminal window. then type fg to return to the emacs editor.
启动终端窗口。在提示下,在 emacs 编辑器中输入“emacs hi.php” 输入一行内容为 print "hi world" 输入 cntl xs 以保存您的文件,然后输入 cntl-z 以退出到终端窗口,然后输入 php hi.php 您应该请参阅终端窗口中显示的“hi world”。然后输入 fg 返回到 emacs 编辑器。