[英]How can I run a php without a web server?
I would like to ask if I can run a php without having installed a web server. 我想问一下我是否可以在没有安装Web服务器的情况下运行php。 Do I have to use the php like CGI and run my page via command line? 我是否必须使用像CGI这样的php并通过命令行运行我的页面? And if so, what are the steps that I do I have to choose through the installation of php? 如果是这样,我必须通过安装php来选择哪些步骤? I mean the preferences as CGI and the components after that step? 我的意思是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. 我安装了php 5.3.3,但似乎无法正常工作,我收到几条消息,说明缺少php5ts.dll,当我把那个文件放在我的ext文件夹中时,会出现其他错误消息。 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适合做这样的事吗?)
If I have to have a web server installed how can I run my php code through the command line? 如果我必须安装Web服务器,如何通过命令行运行我的PHP代码?
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. 值得补充的是,5.4版以后的PHP能够自行运行Web服务器。 You can do it by running this code in a folder which you want to serve the pages from: 您可以通过在要从中提供页面的文件夹中运行此代码来执行此操作:
$ php -S localhost:8000
You can read more about running a PHP in a Web Server mode here . 您可以在此处阅读有关在Web服务器模式下运行PHP的更多信息。
For windows system you should be able to run php by following below steps: 对于Windows系统,您应该能够通过以下步骤运行PHP:
$ php -S localhost:8000
command in a folder which you want to serve the pages from. 在要从中提供页面的文件夹中调用$ php -S localhost:8000
命令。 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 slim app 但是我正在与它抗争,尝试运行一个苗条的应用程序
PHP is a normal sripting language similar to bash or python or perl. PHP是一种类似于bash或python或perl的普通sripting语言。 So a script with shebang works, at least on linux. 因此,shebang的脚本至少可以在linux上运行。
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
You can use these kind of programs to emulate an apache web server and run PHP on your computer: 您可以使用这些类型的程序来模拟Apache Web服务器并在您的计算机上运行PHP:
http://www.wampserver.com/en/ http://www.wampserver.com/en/
http://www.apachefriends.org/en/xampp.html http://www.apachefriends.org/en/xampp.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.