How to run php files on my computer

PhpApache

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

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

Solution 2 - Php

You have to run a web server (e.g. Apache) and browse to your localhost, mostly likely on port 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).

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.

Again, regardless of whether or not you choose XAMPP (which I would recommend), you should just have to start Apache.

Solution 3 - 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

Solution 4 - Php

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

Solution 5 - Php

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

Solution 6 - 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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionloganView Question on Stackoverflow
Solution 1 - Phppeter zhangView Answer on Stackoverflow
Solution 2 - PhpBhaxyView Answer on Stackoverflow
Solution 3 - PhpSlavaNovView Answer on Stackoverflow
Solution 4 - Phpuser3603181View Answer on Stackoverflow
Solution 5 - PhpProdoElmitView Answer on Stackoverflow
Solution 6 - PhpApurv ThakurView Answer on Stackoverflow