Learning PHP Part 5 : How to Run PHP Files with XAMPP


After we practice how to run Apache web server with XAMPP, in this tutorial we are going to try to run the PHP file directly through the application of XAMPP.

Know your htdoc Folder

In order to access a PHP page from a web browser, then you should put the PHP file in a special folder that is the home folder of the web server.

On the application, a folder XAMPP htdocs folder is located in the installation folder of XAMPP. If you change the place of installation of XAMPP into D:xampp (if you follow the tutorial before), then those folders should be in D:\xampp\htdocs.

How to-Run PHP-files-Folders-Location-htdoc

You can put PHP files directly in this folder, or in order to facilitate the search of files, create a new folder in the htdocs folder. For tutorial learn PHP in this webspoint, I’ll create a folder “learning“. It is this learning folder which we will use as the site of the PHP file.

How To Write A PHP File

PHP file is basically a text file that can be created using the default windows notepad application, but for more features, you can use a text editor application such as Notepad ++, which can be downloaded at http://notepad-plus-plus.org/download/. How to installation application Notepad ++ I’ve ever discussed in Tutorial HTML: select HTML Editor Application.

Back to the learning which is at D:\xampp\htdocs\learning, we will create a new file. For the creation of this file, you can use the default Windows notepad or Notepad ++.

As the field of the file, please type the following code :

Then save as a try.php. So that the file will be located at the address D:\xampp\htdocs\learning\try.php. Up to this point, in fact we’ve created a simple PHP file. To run it, we should be using a web browser.

How To Run PHP Files

If the Apache Web Server has not been running, please start it first, as in the tutorial how to run Apache Web Server with XAMPP.

Next, open the browser, and type the following address: localhost/learn/try.php in the address bar and press Enter.

If you followed the above steps correctly, then in the web browser will appear as a display in the following:

How To-Run PHP-Files-Hello-World

Congratulations! You have successfully run the PHP file you first, though PHP file is not working on anything other than display a few lines of text.

Before the end of this tutorial, there are several things to note related how to run a PHP file :

  • Php file which will be executed must reside in the folder D:xampphtdocs, be it in the folder, or folder-the folder below. To run in the browser, you can just replace the address D:xampphtdocs be localhost. However, If the php files are outside the folder htdoc, then the web server could not access it.
  • Every PHP file should be written using the suffix. php (although this can be changed in the settings module php).
  • Naming PHP files should be unspaced, and preferably use lower case. You can use the underscore (_) as a substitute for a space.

Up here, we have learned how to run a PHP file on Apache web server. In the next tutorial we will learn about the workings of a web server running PHP.



Please enter your comment!
Please enter your name here