在 ubuntu linux 服务器上通过命令行运行 php 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12157163/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:57:24  来源:igfitidea点击:

Run php file via command line on an ubuntu linux server

php

提问by kayfun

I am trying to run a php file on a ubuntu linux server but get a 'command not found' error when i run "php file_name.php"

我正在尝试在 ubuntu linux 服务器上运行一个 php 文件,但是当我运行“php file_name.php”时出现“找不到命令”错误

Searching online, i found an article that suggested I run "sudo aptitude install php5-cli" which I did and restarted apache afterwards but I still get this error.

在网上搜索,我发现一篇文章建议我运行“sudo aptitude install php5-cli”,然后我做了并重新启动了apache,但我仍然收到此错误。

How do I fix this?

我该如何解决?

回答by Learner

Try this once,

试试这个,

Go to terminal.

去终端。

whereis php

It will show where is php installed.

它将显示安装了 php 的位置。

Export that path to environment variable using following command

使用以下命令将该路径导出到环境变量

export PATH=$PATH;/path/to/php's/bin directory

Then execute required file..

然后执行所需的文件..

As follows,

如下,

php file_to_execute.php

回答by Ace

first make sure that you've installed following packs:

首先确保您已安装以下包:

  • php5
  • php5-cli
  • php-pear
  • php5
  • php5-cli
  • php-梨

like this:

像这样:

sudo apt-get install php5 php5-cli php-pear

then make sure to configure php safely befor using it.

然后确保在使用它之前安全地配置php。

also make your php file executable ( chmod 700 )

还使您的 php 文件可执行( chmod 700 )

回答by nitin

  • Try the following step :
  • Open your cmd/console or press ctr+alt+t.
  • php5 /your/path/to/php_file_name.
  • 尝试以下步骤:
  • 打开您的 cmd/控制台或按 ctr+alt+t。
  • php5 /your/path/to/php_file_name.php