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
Do I need to use XAMPP for PHP development?
I highly recommend using Laragon instead of XAMPP. It's more user friendly and provides a lot more tools you will end up needing anyways. More on reddit.com
๐ŸŒ r/webdev
7
3
April 1, 2021
Is XAMPP for beginners or is XAMPP used by professionals as local dev environment?
First a bit of history. Back when I started out learning how to setup servers, I remember XAMPP being promoted as the beginner-friendly alternative to setting up your own servers. I think I even tried it out a few times, but the nerds, at the time โ€” those hanging out on the forums โ€” was advising people to install servers manually, since they would learn more, so that was what I did. This was before the time of social media FYI, so the tone was very rough on these forums โ€” if you asked a question before Googling and doing your homework, you would be crushed! Last time I tried XAMPP I actually found it to be confusing and complicated, since stuff was stored in non-standard locations. Etc. In the end I gave up and just installed Apache + MySQL + PHP the old fashioned way, and I find that works very well for me. You got to remember, in Ubuntu at least, it is just a simple matter of running: sudo apt install apache2 PHP8.0 mysql-server php8.0-fpm It is extremely easy to setup, and the location of configuration files is very intuitive once you get used to Linux. Even setting up Let's Encrypt is a matter of typing a few commands in terminal. I do not think it can get much easier than that. More on reddit.com
๐ŸŒ r/PHP
167
64
February 7, 2021
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
People also ask

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
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
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 will be able to code and test your PHP applications locally after completing this process. ... Navigate to the XAMPP installation directory (C:\xampp\htdocs) and create a new folder for your project. For example, name it demo.
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ how-to-run-php-programs
How to run PHP programs ? - GeeksforGeeks
July 23, 2025 - Open XAMPP and start the Apache server. Write the below code in your index.php file. ... This will run your PHP script through the local server and display the output in the browser.
Find elsewhere
๐ŸŒ
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'.
๐ŸŒ
EITCA
eitca.org โ€บ home โ€บ how can you create and run a php file using xampp?
How can you create and run a PHP file using XAMPP? - EITCA Academy
August 8, 2023 - โ€“ Save your PHP file with an appropriate name and the ".php" extension. For instance, "C:xampphtdocsmyfile.php". 5. Run the PHP file: โ€“ Open a web browser (e.g., Chrome, Firefox) and enter the following URL in the address bar: "http://localhost/myfile.php".
๐ŸŒ
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?
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-get-started-with-php
PHP Tutorial โ€“ How to Setup PHP and XAMPP for Your Project
October 8, 2024 - The opening tag is <?php then your ... Then save it. After writing the code, open the XAMPP control panel, and start the Apache module by clicking on start under the action section....
๐ŸŒ
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.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ blog โ€บ software development โ€บ how to use xampp for php files? (stepwise approach)
How to Use XAMPP For PHP Files? (Stepwise Approach)
April 14, 2025 - This folder is essential because the browser accesses PHP files from it via http://localhost. To view the file, open your browser and go to http://localhost/test.php. If everything is set up correctly, you should see a page with detailed information ...
๐ŸŒ
YouTube
youtube.com โ€บ webly
How to run PHP file on localhost XAMPP | open php file in browser - YouTube
In this video we will learn to how to run PHP files on localhost using XAMPP in Windows.Useful LinksXAMPP - https://www.apachefriends.org/index.htmlWATCH How...
Published ย  February 26, 2025
Views ย  158K
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ how-to-execute-php-script-in-website-using-xampp-webserver
How to execute PHP Script in Website using XAMPP webserver ? - GeeksforGeeks
December 1, 2020 - Open XAMPP control panel, if you want to link database to your code then start MySQL otherwise you will need to start Filezilla and Apache ... Then open Notepad/Notepad++ or any text editor to write PHP program.
๐ŸŒ
ExamSnap
examsnap.com โ€บ home โ€บ how to run php files locally using xampp: step-by-step tutorial for beginners
How to Run PHP Files Locally Using XAMPP: Step-by-Step Tutorial for Beginners - ExamSnap
December 19, 2025 - Save the file with a .php extension inside your project folder. For example, create a file named index.php inside myproject and write the following: ... To run the PHP script, make sure Apache is running via the XAMPP Control Panel. Open your preferred web browser and type the URL:
๐ŸŒ
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 - We have created a file with the name, FirstProgram.php. ... Step 5: Go to the start button, and type Xampp Server to open it. This will open Xampp Server- Control Panel. After opening it, just click Start on Apache to start the server: Step ...
๐ŸŒ
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 ย  April 13, 2022
๐ŸŒ
YouTube
youtube.com โ€บ microng
How to run first PHP program in XAMPP Server - YouTube
How to run first PHP program in XAMPP Server. XAMPP Server is the most popular PHP development environment. XAMPP is a completely free, easy to install Apach...
Published ย  August 17, 2025
Views ย  47K
๐ŸŒ
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 - Create your PHP file inside the htdocs folder. Make sure to place all your PHP files inside the htdocs folder to run them correctly. Run the file in the browser using localhost by typing http://localhost/file_name.php.