How to run your first PHP Program - XAMPP

How to run PHP Program in XAMPP

To begin Programming in PHP, almost everyone is faced with this simple but obvious question:

How to easily run PHP Program for the first time?

Answer: The easiest way to start with PHP Programming is using the software bundle named XAMPP (I'll update this post from time to time to meet the visitors' interests):

You don't have to install Apache, PHP and MySQL separately, in fact, it is often difficult for beginners to install these bundles separately and combine them to run PHP. XAMPP does that for you with just a few clicks.

In Windows, before you install XAMPP, you'll have to uninstall existing Apache and MySQL installation (if they were installed as a service). If they were not installed as a service, then you may or may not uninstall them, it's up to you (and may be up to some unforeseen setting in your system).

After you install XAMPP,

  1. Open any Text Editor.
    Install new if you don't already have any good Text Editor installed. (My Favorite is Sublime Text & Notepad++)
  2. Write the following PHP Program in the Text Editor:
    echo 'Running My First PHP Program in XAMPP! <br />';
    This is test.php File.
  3. Save the file in XAMPP Installation Directory \ Web Root Directory
    Note-1: Default XAMPP Installation Directory in Windows is C:\xampp
    Note-2: Default Web Root Directory in XAMPP is htdocs. All your php files will have to be in this htdocs folder.
    That means, for a typical installation of XAMPP in Windows, you will have to save the PHP Program in C:\xampp\htdocs folder.
  4. When you save the file, name it (for example) test.php
    Note: when you save this file, make sure it has no .txt extension at the end. Some text editors place .txt at the end of file name, so it becomes test.php.txt instead of test.php. To avoid this, when you save the file using any text editor, place double quote around the file name: e.g. "test.php"
  5. Then, go to XAMPP installation folder (typically, C:\xampp) and run xampp-control.exe by double clicking it.
  6. In the xampp-control window, click the start button beside Apache. Later, if you need other options like MySQL, you'll also have to start MySQL by clicking the start button beside MySQL in the XAMPP control Panel.
    Note: if your OS hides common file extensions, then you'll see xampp-control, instead of xampp-control.exe
  7. Now, in your web browser's address bar, type the address: http://localhost/test.php

If your test PHP file is working properly, then you should see the following two lines in your browser:

Running My First PHP Program in XAMPP!
This is test.php File.

If PHP is NOT working (but the web server Apache is working), in that case only the following one line result will appear:

This is test.php File.

If none of the above is happening, then you are doing something wrong somewhere else.

So there goes your first PHP Program in XAMPP. Happy Coding :)

Further Reading:

  1. PHP Manual
  2. Easy PHP Tutorial
  3. Another PHP Tutorial for Beginners
  4. Book: Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5

17 comments on “How to run your first PHP Program - XAMPP”

  1. Thanks for the information. I wanted to start web development using PHP.

    But, It gave me a headache when I tried to install Apache, PHP and MySQL all together. Also, I heard sometimes you need the matching versions of those software to work together properly.

    XAMPP saved the day! Now I can easily follow web development tutorials in my off time.

  2. i am working now on xampp wap server sql database, and i am tring to rum php code in xamp but i can't find place to coding php script and run.please help me anyone.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use the following HTML tags and attributes, but please be nice:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>