简体   繁体   English

在Linux命令行中运行PHP

[英]Run PHP in Linux Command Line

I wrote a test file named phpinfo.php which path in CentOS is /var/www/html/phpinfo.php . 我写了一个名为phpinfo.php的测试文件,它在CentOS中的路径是/var/www/html/phpinfo.php There is no browser, is there a way to run the file and see the output? 没有浏览器,有没有一种方法可以运行文件并查看输出?

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) 第一个从命令行运行脚本,第二个从Web服务器获取脚本(假定您已正确配置了脚本)

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. 如果要通过Web服务器访问它,则需要确保将服务器配置为运行PHP脚本,然后发出HTTP请求。 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. 可以通过网络访问服务器在一个计算机上安装一个或在另一个计算机上使用一个计算机。

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格式进行打印。

您需要使用。

php /var/www/html/phpinfo.php 

您通常会执行以下操作:

php /var/www/html/phpinfo.php

您可以使用命令行:

php /var/www/html/phpinfo.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM