How to run PHP Program for the first time? use XAMPP.

Easiest way to start PHP: Run PHP program in XAMPP

How to run PHP Program in XAMPP

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

How to run PHP Program for the first time? What's the easiest way?

Answer: The easiest way to run a PHP Program for the first time (for web development) is using the software bundle named XAMPP. There are other similar software bundles that can run PHP, but:

XAMPP works well in all the major platforms: Windows, Mac and Linux.

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 CODE. XAMPP does that for you with just a few clicks.

Before you install XAMPP, you may have to uninstall existing Apache and MySQL installations, especially if they were installed as a service.

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 / CODE in the Text Editor:
    <?PHP
    echo 'I know how to run a 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 CODE in C:\xampp\htdocs folder.
  4. When you save the file, name it test.php (just as an example, any valid file name with .php in the end will work).
    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:

I know how to run a 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 now you know how to run PHP Program in XAMPP. It is time to learn some web development with PHP! Happy Coding 🙂

Further Reading:

  1. PHP Manual
  2. PHP Tutorial for Beginners

90 thoughts on “How to run PHP Program for the first time? use XAMPP.”

    1. It shows this error message when I hit start.

      "

      PM 12:54:21 [Apache] Attempting to start Apache app...
      PM 12:54:22 [Apache] Status change detected: running
      PM 12:54:25 [Apache] Status change detected: stopped
      PM 12:54:25 [Apache] Error: Apache shutdown unexpectedly.
      PM 12:54:25 [Apache] This may be due to a blocked port, missing dependencies,
      PM 12:54:25 [Apache] improper privileges, a crash, or a shutdown by another method.
      PM 12:54:25 [Apache] Press the Logs button to view error logs and check
      PM 12:54:25 [Apache] the Windows Event Viewer for more clues
      PM 12:54:25 [Apache] If you need more help, copy and post this
      PM 12:54:25 [Apache] entire log window on the forums

      "

      What to do?

  1. i have some php file ready to run some kind of software to send emails. how can i place file on proper folder to run this software. urgent help needed.

  2. It works well!!! I started learning PHP today and have been struggling to run the code in a browser until I came to this page.
    Thanks a million.

  3. it shows an error whenever click on start:
    7:55:32 PM [mysql] Status change detected: stopped
    7:55:32 PM [mysql] Error: MySQL shutdown unexpectedly.
    7:55:32 PM [mysql] This may be due to a blocked port, missing dependencies,
    7:55:32 PM [mysql] improper privileges, a crash, or a shutdown by another method.
    7:55:32 PM [mysql] Press the Logs button to view error logs and check
    7:55:32 PM [mysql] the Windows Event Viewer for more clues
    7:55:32 PM [mysql] If you need more help, copy and post this
    7:55:32 PM [mysql] entire log window on the forums

    what should i do??

    1. Exit XAMPP, then:
      1. Go to MySQL data directory (default in Windows is: C:\xampp\mysql\data)
      2. Rename the ibdata1 file to something else (for example: ibdata1.backup)
      3. Restart XAMPP control & try to start MySQL again.
      Should work.

    1. I Need some details before I can answer:

      1. What is the name of your PHP file/script?
      2. Where did you place this file (full path of the file)?
      3. Copy the exact PHP CODE
      4. What did you enter in your browser address bar?

  4. Object not found!

    The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

    If you think this is a server error, please contact the webmaster.
    Error 404
    localhost
    Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.13
    this error is showing

Leave a Reply

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