First you need to start XAMPP. So, go to the drive where you install the XAMPP server. Generally, it's installed in C drive. So, go to C:\xampp\ . And open the file xampp-control.exe . When the controller open you need to start the Apache and Mysql . Then you see the green color besides Apache and Mysql . It means they are running or started. OK. Now, go to C:\xampp\htdocs and create a folder as you want. For an example you can create folder which name is hello . Then open this folder and create a file which name is index.php and open it in you editor write a basic code like this:

<?php echo "Hello World"; ?>

Then save it. And open your browser. And go to localhost/hello

hello means the folder name you created. Now, you will see the output. Which showing Hello World

Feel free to asking any question. Happy Coding!!

Answer from acoder on Stack Overflow
🌐
Simplilearn
simplilearn.com › home › resources › software development › how to run a php file using xampp: a step by step guide
How to Run a PHP File Using XAMPP: A Step By Step Guide
July 31, 2025 - Check out the ways to run a PHP file using XAMPP. Explore what XAMPP is and how can it be installed on your system. Read on to know how to execute a PHP script!
Discussions

Does PHP only work inside C:\xampp\htdocs with a localhost?
Php files techincally can work anywhere on your system if you manually call them (example assuming default install) c:\xampp\php\php.exe c:\path\to\your\phpfile.php However, to work in a browser, yes, it can only work inside certain directories, defined in your apache.conffile. You can define other locations in there, but by default, it just sets up the one site location. EDIT to expand a little more: When you open a location in your browser, it takes what it finds and renders it. If you call to http://localhost/ that is making a call to Apache running on your computer, which then will via the config file, look for a given file (or assumed defaults if a specific file isn't given), and then processes it and returns the output to the browser. In the case of a plain .html file (and other basic asset files) it will just pass them through. However for specially defined file types (like php ones), it will first pass the file to be processed by PHP, and then the output of PHP gets passed to the browser. This is why you can't interact with a PHP file during execution, it is always fully processing then you get output (well technically, it can send part of the output while processing, but generally it happens so fast, you don't notice) However if in your browser you directly call the file, ie browse to file:\\\xampp\htdocs\sample.php your browser is directly loading the file from the file system and rendering the "output" ends up rendering the raw php code, since nothing processed it. More on reddit.com
🌐 r/PHPhelp
21
8
January 21, 2023
Opening /running PHP files in Mac
php -S localhost:8000 will start a test server using the index.php in your current working directory. https://www.php.net/manual/en/features.commandline.webserver.php More on reddit.com
🌐 r/webdev
6
0
August 9, 2022
XAMPP can't read my Javascript in my PHP file, but it will when it's HTML?

src="scripts.js"

The most likely reason for this is that 'scripts.js' isn't in the right place when you access this file.

  1. Learn to use Dev Tools

  2. XAMPP can't read your javascript? No. XAMPP is the package/framework. Your browser can't read your javascript and the browser is the best place to find out why.

More on reddit.com
🌐 r/webdev
12
10
February 11, 2015
XAMPP - index.html -> index.php
XAMPP should have that by default, not sure what went wrong with your install. One thing I'll also suggest is try laragon, much better windows server More on reddit.com
🌐 r/PHPhelp
12
1
August 27, 2023
People also ask

Can we run PHP in XAMPP?
Yes, you can run PHP in XAMPP. First, start the XAMPP server, create a program you want to and run it at http://localhost.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › how to run a php file using xampp: a step by step guide
How to Run a PHP File Using XAMPP: A Step By Step Guide
Q1. How to run PHP file in XAMPP on Windows?
You can run a PHP file in XAMPP by saving it inside the htdocs directory, starting the Apache icon in the XAMPP control panel, and accessing http://localhost/yourfile.php in your web browser.
🌐
intellipaat.com
intellipaat.com › home › blog › how to run php file using xampp
How to Run a PHP File using XAMPP - Step by Step Guide
Q8. Why is my PHP file not running in XAMPP?
Your PHP file may not be in the htdocs folder or Apache isn’t running in XAMPP.
🌐
intellipaat.com
intellipaat.com › home › blog › how to run php file using xampp
How to Run a PHP File using XAMPP - Step by Step Guide
🌐
Devrims Blog
devrims.com › home › php › how to run a php file using xampp
How to Run a PHP File Using XAMPP - Devrims Blog
January 24, 2025 - You may easily test and debug your PHP code locally by following these easy steps. ... Open your preferred web browser. In my case, I am using Google Chrome. ... Type (http://localhost/demo) in the address bar and press Enter.
🌐
Reddit
reddit.com › r/phphelp › does php only work inside c:\xampp\htdocs with a localhost?
r/PHPhelp on Reddit: Does PHP only work inside C:\xampp\htdocs with a localhost?
January 21, 2023 -

If I try to put a php file inside any other location other than whats listed in the title, it just shows the code and doesnt execute it. Is there a way around this?

Top answer
1 of 8
9
Php files techincally can work anywhere on your system if you manually call them (example assuming default install) c:\xampp\php\php.exe c:\path\to\your\phpfile.php However, to work in a browser, yes, it can only work inside certain directories, defined in your apache.conffile. You can define other locations in there, but by default, it just sets up the one site location. EDIT to expand a little more: When you open a location in your browser, it takes what it finds and renders it. If you call to http://localhost/ that is making a call to Apache running on your computer, which then will via the config file, look for a given file (or assumed defaults if a specific file isn't given), and then processes it and returns the output to the browser. In the case of a plain .html file (and other basic asset files) it will just pass them through. However for specially defined file types (like php ones), it will first pass the file to be processed by PHP, and then the output of PHP gets passed to the browser. This is why you can't interact with a PHP file during execution, it is always fully processing then you get output (well technically, it can send part of the output while processing, but generally it happens so fast, you don't notice) However if in your browser you directly call the file, ie browse to file:\\\xampp\htdocs\sample.php your browser is directly loading the file from the file system and rendering the "output" ends up rendering the raw php code, since nothing processed it.
2 of 8
2
Its not possible to "execute" a php file outside of the web directory, directly in the browser. You can have a php script include another php scripts code and that script can be anywhere you have read access to. The reason you are seeing the php code is (Im guessing) because you are not loading the script through the webserver (http://localhost) and instead are just loading a txt file inti the browser?
🌐
Edureka
edureka.co › blog › how-to-run-a-php-program-in-xampp
How to Run a PHP program in Xampp? Step by Step Guide | Edureka
July 23, 2024 - We can use the php command followed by the file name to run the PHP script on command line. php <file_name.php> Use local web servers to host the PHP file. It can be accessed using http://localhost/<file_name.php> on the Chrome browser.
🌐
Medium
medium.com › @lostorto.business › how-to-run-php-with-xamp-d3318f7a7735
How To: Run PHP with XAMPP. Step by step instructions on how to… | by Alex lo Storto | Medium
November 15, 2023 - 6. If the server has started successfully, then you should be able to go to your browser and visit http://localhost to get something like the picture below (yours will look different depending on what folders you have inside and where you defined your root directory). Now that we’ve set up your local server, you can already start running your PHP files. However, if you don’t want to place your files in the default C:\xampp\htdocs directory, you can alter the httpd.conf file to change the root directory.
Find elsewhere
🌐
Studyopedia
studyopedia.com › home › run your first php program in xampp server on localhost
Run your first PHP program in XAMPP Server on localhost - Studyopedia
July 20, 2025 - Let’s start with installing XAMPP, and running the first PHP program using XAMPP Server on localhost. The following are the steps: ... Step 1: Go to the Apache Friends website and download XAMPP Server.
🌐
YouTube
youtube.com › watch
How to Run PHP Files on Localhost with XAMPP (2024 Update) - YouTube
In this video, I'll show you how you can run PHP files on localhost with XAMPP. We will use Apache server that is bundled into XAMPP to server our PHP files....
Published   March 16, 2024
🌐
Medium
alinawrites.medium.com › how-to-run-php-file-on-localhost-e740890fcdff
How To Run PHP File On Localhost. Most articles and tutorials are written… | by Alina Writes | Medium
November 2, 2022 - This will run the php code in the file and display the results. You can also pass arguments to the php file using this syntax: ... You can use any number of arguments you want. Just make sure to separate them with spaces. https://semicolon.dev/php/how-to-run-php-on-localhost-xampp
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-run-php-programs
How to run PHP programs ? - GeeksforGeeks
July 23, 2025 - Once set up, you can create PHP files with a .php extension and place them in the server's root directory (e.g., htdocs for XAMPP). After starting the server, you can access the PHP file in your browser using http://localhost/filename.php.
🌐
YouTube
youtube.com › geeky script
How to Run PHP file on localhost | Windows 10 [ 2022 Update ] Complete guide for using XAMPP Server - YouTube
Hello Everyone! Today in this video I am going to step-by-step guide you on How to Run PHP file on localhost. In that process, you will also get to know abo...
Published   December 30, 2025
Views   489K
🌐
Jonah Lawrence
jonahlawrence.hashnode.dev › how-to-run-an-htmlphp-website-on-localhost
How to run an HTML/PHP website on Localhost
September 15, 2025 - Type the command php -S localhost:8000 to run your site on port 8000. Note: If you get an error that 'php' is not recognized, you likely will need to add it to your path manually.
🌐
LinkedIn
linkedin.com › pulse › how-run-php-file-using-xampp-step-data-ins-technology-llc
How to Run a PHP File Using XAMPP: A Step By Step
October 13, 2023 - Access the PHP File: Open your web browser and enter the following URL: 'http://localhost/yourfile.php, where 'yourfile.php' is the name of your PHP file. In this example, it would be 'http://localhost/index.php'.
🌐
Hashnode
jst.hashnode.dev › running-simple-php-file-on-localhost-xampp
Running Simple PHP File on Localhost (XAMPP)
July 30, 2022 - If you want to run PHP files on your local machine, you will need to set up a local server environment. One of the most popular ways to do this is by using XAMPP. XAMPP is a free and open source cross-platform web server solution stack package ...
🌐
Quora
quora.com › How-do-I-use-a-PHP-server-on-a-local-host
How to use a PHP server on a local host - Quora
You need to go into the installation directory of xampp -> htdocs-> create a folder. Create a file in this folder. After that in browser you need to type localhost/folder name/filename · The php file will run.
🌐
DEV Community
dev.to › aakriti_sharma › how-to-run-php-and-link-to-mysql-using-xampp-57lh
How to run PHP and link to MySQL using XAMPP - DEV Community
November 30, 2020 - If you use VSCode, change php.validate.executablePath = "C://PHP7//php.exe" in settings.json Install the Code Runner Extension and run the file from terminal itself. Go to https://www.apachefriends.org/download.html and download the latest version ...
🌐
YouTube
youtube.com › watch
How To Run PHP on Localhost with XAMPP for Windows (And edit PHP in Visual Studio Code) - YouTube
Sign Up 👻👻👉 https://semicolon.dev/YouTube(We're free online community, meet other makers!)#php #xampp #localhost #windows How To Open PHP File on Localho...
Published   June 19, 2023
🌐
Acciyo
acciyo.com › setting-up-and-running-your-first-php-project-with-xampp-on-localhost
Setting Up and Running Your First PHP Project with XAMPP on Localhost
March 16, 2024 - Naming it index.php will make it the default file loaded when you access the project folder in your browser. ... Open your web browser. In the address bar, type http://localhost/ to access the XAMPP dashboard and verify that Apache is running.
🌐
Techwalla
techwalla.com › around the home › productivity
How to Run a PHP File in XAMPP | Techwalla
February 9, 2017 - The browser will open a list of files stored under the "HTDocs" folder on your computer. Click on the link to a PHP file and open it to run a script. ... Create any folders you need to test PHP files in under the "HTDocs" folder.
🌐
Intellipaat
intellipaat.com › home › blog › how to run php file using xampp
How to Run a PHP File using XAMPP - Step by Step Guide
September 5, 2025 - This is the core process of how to run a PHP file in XAMPP. Open xampp-control.exe. Remember to run as an administrator. Right-click and select “Run as administrator” to avoid permission issues.