在 Linux 命令行中运行 PHP

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

Run PHP in Linux Command Line

phplinuxcommand-linecentoscommand-line-interface

提问by zhuanzhou

I wrote a test file named phpinfo.phpwhich path in CentOSis /var/www/html/phpinfo.php. There is no browser, is there a way to run the file and see the output?

我写了一个测试文件,名为CentOS 中的phpinfo.php哪个路径是 . 没有浏览器,有没有办法运行文件并查看输出?/var/www/html/phpinfo.php

采纳答案by zoomix

Yes.

是的。

 - php /var/www/html/phpinfo.php
 - curl http://localhost/phpinfo.php

The first runs the script from commandline, the second fetches it from the webserver (this assumes you've configured it correctly)

第一个从命令行运行脚本,第二个从网络服务器获取它(假设您已正确配置它)

回答by Levi Hackwith

You would usually do something like this:

你通常会做这样的事情:

php /var/www/html/phpinfo.php

php /var/www/html/phpinfo.php

回答by Fabio Cicerchia

you can use the command-line:

您可以使用命令行:

php /var/www/html/phpinfo.php

回答by Quentin

If you want to run it directly on the command line (which seems unlikely as you have placed the file in the webroot):

如果您想直接在命令行上运行它(这似乎不太可能,因为您已将文件放在 webroot 中):

php /path/to/script.php

If you want to access it through the webserver then you need to make sure the server is configured to run PHP scripts, and then make an HTTP request. Using a web browser is the easiest way to do this. Either install one or use one on another machine with network access to the server.

如果您想通过网络服务器访问它,那么您需要确保将服务器配置为运行 PHP 脚本,然后发出 HTTP 请求。使用网络浏览器是最简单的方法。在另一台可以通过网络访问服务器的机器上安装一个或使用一个。

回答by Michael Berkowski

If you are only interested in the output of phpinfo()you can see the same information from the command line with:

如果你只对输出感兴趣,phpinfo()你可以从命令行看到相同的信息:

php -i

This prints it in a console-friendly format, rather than in styled HTML as phpinfo()displays.

这会以对控制台友好的格式打印它,而不是以phpinfo()显示样式的 HTML 格式打印。

回答by mr_eclair

You need to use.

你需要使用。

php /var/www/html/phpinfo.php