在 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
Run PHP in Linux Command Line
提问by zhuanzhou
采纳答案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