简体   繁体   English

如何在没有Web服务器的情况下运行php?

[英]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:

  1. Download php version you want to use and put it in c:\\php. 下载你想要使用的php版本并将其放在c:\\ php中。
  2. append ;c:\\php to your system path using cmd or gui. 使用cmd或gui将c; \\ php附加到系统路径。
  3. call $ 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.

相关问题 如何在不需要Web浏览器的情况下在服务器上运行PHP脚本 - How to run PHP script on server without needing a web browser 我可以在PHP中找到运行Web服务器的用户吗? - Can I find which user the web server is being run as in PHP? 如何从php-web页面centos服务器在后台运行exec()命令 - How can I run exec() command in background from php-web page centos server 我如何在没有Index.html或.php的情况下将WebApplication文件运行到服务器? - How can I run my WebApplication files to the server without an Index.html or.php? 创建可以运行php的Web服务器 - Create Web Server which can run php 如何在PHP中一起运行2个循环而不重复值? - How can I run 2 loops together in PHP without duplicating values? 我可以运行没有apache服务器(没有wamp或xampp)的用php和mysql开发的网站吗? - Can i run my website which is developed in php and mysql without apache server (without wamp or xampp ))? 我如何每月在服务器上运行php脚本而不运行cron作业。 例如使用.htaccess - How can i run a php script on a server every month without running a cron job. e.g. using .htaccess 如何在Web服务器上的php中运行keytool和jarasigner - How to run keytool and jarasigner in php on web server 如何从Web服务器运行php脚本 - How to run php scripts from web server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM