如何在没有 Web 服务器的情况下运行 php?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4301975/
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 can I run a php without a web server?
提问by touinta
I would like to ask if I can run a php without having installed a web server. Do I have to use the php like CGI and run my page via command line? And if so, what are the steps that I do I have to choose through the installation of php? I mean the preferences as CGI and the components after that step?
我想问一下我是否可以在没有安装Web服务器的情况下运行php。我是否必须像 CGI 一样使用 php 并通过命令行运行我的页面?如果是这样,我必须通过安装 php 选择哪些步骤?我的意思是作为 CGI 的首选项和该步骤之后的组件?
I installed the php 5.3.3 but is seems not working, I get several message that the php5ts.dll is missing and when I put that file in my ext folder other error messages appear. Are there any configuration files or steps that I have to use? (is php 5.3.3 suitable for doing something like this?)
我安装了 php 5.3.3 但似乎不起作用,我收到几条消息,指出 php5ts.dll 丢失,当我将该文件放入 ext 文件夹时,会出现其他错误消息。是否有任何我必须使用的配置文件或步骤?(php 5.3.3 适合做这样的事情吗?)
If I have to have a web server installed how can I run my php code through the command line?
如果我必须安装 Web 服务器,如何通过命令行运行我的 php 代码?
回答by Michal M
You should normally be able to run a php file (after a successful installation) just by running this command:
您通常应该能够通过运行以下命令来运行 php 文件(成功安装后):
$ /path/to/php myfile.php // unix way
C:\php\php.exe myfile.php // windows way
You can read more about running PHP in CLI mode here.
您可以在此处阅读有关在 CLI 模式下运行 PHP 的更多信息。
It's worth adding that PHP from version 5.4 onwards is able to run a web server on its own. You can do it by running this code in a folder which you want to serve the pages from:
值得补充的是,从 5.4 版开始,PHP 能够独立运行 Web 服务器。您可以通过在要从以下位置提供页面的文件夹中运行此代码来实现:
$ php -S localhost:8000
You can read more about running a PHP in a Web Server mode here.
您可以在此处阅读有关在 Web 服务器模式下运行 PHP 的更多信息。
回答by Brijesh Kapletiya
For windows system you should be able to run php by following below steps:
对于 Windows 系统,您应该能够通过以下步骤运行 php:
- Download php version you want to use and put it in c:\php.
- append ;c:\php to your system path using cmd or gui.
- call
$ php -S localhost:8000
command in a folder which you want to serve the pages from.
- 下载你要使用的php版本,放到c:\php中。
- 使用 cmd 或 gui 将 ;c:\php 附加到您的系统路径。
$ php -S localhost:8000
在要提供页面的文件夹中调用命令。
回答by Michel Samia
PHP is a normal sripting language similar to bash or python or perl. So a script with shebang works, at least on linux.
PHP 是一种类似于 bash 或 python 或 perl 的普通脚本语言。因此,至少在 linux 上,带有 shebang 的脚本可以工作。
Example PHP file:
示例 PHP 文件:
#!/usr/bin/env php
<?php
echo("Hello World!\n")
?>
How to run it:
如何运行它:
$ chmod 755 hello.php # do this only once
$ ./hello.php
回答by icalvete
See https://github.com/php-pm/php-pm.
请参阅https://github.com/php-pm/php-pm。
Works fine with symphony.
But I'm fighting with it, trying run a slimapp
但我正在与它作斗争,尝试运行一个纤薄的应用程序
回答by Latox
You can use these kind of programs to emulate an apache web server and run PHP on your computer:
您可以使用这些程序来模拟 apache 网络服务器并在您的计算机上运行 PHP: