php 如何在我的电脑上运行php文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8580273/
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 to run php files on my computer
提问by logan
Could anyone please tell me how to run a php file locally on my system.
Currently I am using a server to run files.
I know both php & Apache to be installed.
I need to see out put of this program, for example:
谁能告诉我如何在我的系统上本地运行一个 php 文件。
目前我正在使用服务器来运行文件。
我知道要安装 php 和 Apache。
我需要看看这个程序的输出,例如:
<?php
$a=5;
$b=10;
$c=$a+$b;
print $c;
?>
Can you please tell how I can run these files of if I need anything more.
如果我还需要什么,请告诉我如何运行这些文件。
采纳答案by Bhaxy
You have to run a web server (e.g. Apache) and browse to your localhost, mostly likely on port 80.
您必须运行 Web 服务器(例如 Apache)并浏览到您的本地主机,很可能在端口 80 上。
What you really ought to do is install an all-in-one package like XAMPP, it bundles Apache, MySQL PHP, and Perl (if you were so inclined) as well as a few other tools that work with Apache and MySQL - plus it's cross platform (that's what the 'X' in 'XAMPP' stands for).
您真正应该做的是安装一个像XAMPP这样的多合一软件包,它捆绑了 Apache、MySQL PHP 和 Perl(如果您愿意的话)以及一些其他与 Apache 和 MySQL 一起使用的工具 - 加上它跨平台(这就是“XAMPP”中的“X”代表的含义)。
Once you install XAMPP (and there is an installer, so it shouldn't be hard) open up the control panel for XAMPP and then click the "Start" button next to Apache - note that on applications that require a database, you'll also need to start MySQL (and you'll be able to interface with it through phpMyAdmin). Once you've started Apache, you can browse to http://localhost.
一旦你安装了 XAMPP(并且有一个安装程序,所以应该不难)打开 XAMPP 的控制面板,然后单击 Apache 旁边的“开始”按钮 - 请注意,在需要数据库的应用程序上,您将还需要启动 MySQL(您将能够通过 phpMyAdmin 与它交互)。启动 Apache 后,您可以浏览到http://localhost。
Again, regardless of whether or not you choose XAMPP (which I would recommend), you should just have to start Apache.
同样,无论您是否选择 XAMPP(我会推荐它),您都应该只需要启动 Apache。
回答by SlavaNov
In short:
简而言之:
Install WAMP
Put this file to C:\wamp\www\ProjectName\filename.php
Go to browser: http://localhost/ProjectName/filename.php
安装WAMP
把这个文件放到 C:\wamp\www\ProjectName\filename.php
回答by peter zhang
php have a easy way to run a light server:
first cd into php file directory, then
php 有一个简单的方法来运行轻服务器:
首先 cd 进入 php 文件目录,然后
php -S 127.0.0.1:8000
then you can run php
然后你可以运行php
回答by ProdoElmit
If you have apache running, put your file in server folder for html files and then call it from web-browser (Like http://localhost/myfile.php).
如果您正在运行 apache,请将您的文件放在 html 文件的服务器文件夹中,然后从网络浏览器(如http://localhost/myfile.php)调用它。
回答by user3603181
I just put the content in the question in a file called test.php
and ran php test.php
.
(In the folder where the test.php
is.)
我只是将问题中的内容放在一个名为test.php
并运行的文件中php test.php
。(在 所在的文件夹中test.php
。)
$ php foo.php
15