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.
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.
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
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 ).
I just put the content in the question in a file called
test.php and ran
(In the folder where the
$ php foo.php 15