Home » Php » apache – How to run php files on my computer

apache – How to run php files on my computer

Posted by: admin April 23, 2020 Leave a comment


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:

print $c;

Can you please tell how I can run these files of if I need anything more.

How to&Answers:

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.


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


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

php -S

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 php test.php.
(In the folder where the test.php is.)

$ php foo.php