[php] How to run php files on my computer

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 
$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.

This question is related to php apache

The answer is


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.)

$ php foo.php                                                                                                                                                                                                                                                                                                                                    
15

php have a easy way to run a light server:
first cd into php file directory, then

php -S 127.0.0.1:8000

then you can run php


In short:

  1. Install WAMP

  2. Put this file to C:\wamp\www\ProjectName\filename.php

  3. Go to browser: http://localhost/ProjectName/filename.php


3 easy steps to run your PHP program is:

  1. The easiest way is to install MAMP!

  2. Do a 2-minute setup of MAMP.

  3. Open the localhost server in your browser at the created port to see your program up and runing!


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 ).