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, 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 is using the software bundle named XAMPP:

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. Happy Coding 🙂

Further Reading:

  1. PHP Manual
  2. PHP Tutorial for Beginners

68 thoughts on “How to run PHP Program for the first time? use 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.
    thanks

  3. Hello

    Thanks its working.

    Can you please explain in which scenario will this happen:

    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.

    What do you mean by PHP not working.

    1. Apache is the web server, so even without installing PHP (which is the backend language interpreter) web server will work. So in the event that you didn't install PHP properly or failed to configure it, web server will still serve the file, but it will fail to produce any result from your PHP CODE. So output will be everything that is not enclosed in PHP tag.

  4. Error: Apache shutdown unexpectedly.
    10:33:40 PM [Apache] This may be due to a blocked port, missing dependencies,
    10:33:40 PM [Apache] improper privileges, a crash, or a shutdown by another method.
    10:33:40 PM [Apache] Press the Logs button to view error logs and check
    10:33:40 PM [Apache] the Windows Event Viewer for more clues

      1. Most likely case is you are running Skype in port 80
        Web server runs on port 80 as well.

        Or perhaps, your firewall is blocking port 80. Google for more information.

  5. iam new to xampp now installed xampp how can create login.php file by using xampp and how can i open in xampp please help me iam very new to this

  6. I have installed xampp and its running properly when I run as an admin. But when i type localhost in the address bar, it shows network error as follows:
    "Network Error (dns_unresolved_hostname)
    Your requested host "localhost" could not be resolved by DNS.
    For assistance, contact your network support team."
    Kindly provide me with a solution.

    1. Hi Priya,

      Instead of localhost, try this in your browser:
      http://127.0.0.1/test.php

      If this works, after replacing "localhost" with 127.0.0.1 then I know exactly what the problem is. Let me know about the result.

      If this doesn't work, then I don't know what the problem is. Need more information about your operating system in that case.

  7. PM 2:55:12 [Apache] Error: Apache shutdown unexpectedly.
    PM 2:55:12 [Apache] This may be due to a blocked port, missing dependencies,
    PM 2:55:12 [Apache] improper privileges, a crash, or a shutdown by another method.
    PM 2:55:12 [Apache] Press the Logs button to view error logs and check
    PM 2:55:12 [Apache] the Windows Event Viewer for more clues
    PM 2:55:12 [Apache] If you need more help, copy and post this
    PM 2:55:12 [Apache] entire log window on the forum

    this error is coming when i start appache

  8. Hi Mr. fayaz

    I try the xampp this is my first time. And i understand the process about xampp but i am doubt about the result when i run the first sample in the http://localhost/test.php and the result is this.

    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

    127.0.0.1
    Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.21

    What is this?
    Error !
    what do you mean by two lines mr. fayaz.

    thanks looking forward for your response.

  9. i am getting the 404 file not foung error because the port is not set for apache server i need to set the port how should i do it

    1. Web server default port is 80 and it's normally set automatically by Apache, unless you are using Skype (or some other software) and that is using port 80 already. In that case you'll have to disable port 80 from Skype settings.

      However, 404 is normally not shown for port, it's shown if the file you are trying to access from browser doesn't actually exist in web server root directory.

      So make sure the file exist and there is no typing mistake in the link you are trying to access in the browser.

  10. Its showing error...
    [Mon Jul 18 16:28:52.020621 2016] [ssl:warn] [pid 6128:tid 388] AH01909: http://www.example.com:443:0 server certificate does NOT include an ID which matches the server name
    [Mon Jul 18 16:28:52.476219 2016] [ssl:warn] [pid 6128:tid 388] AH01909: http://www.example.com:443:0 server certificate does NOT include an ID which matches the server name
    [Mon Jul 18 16:28:52.742248 2016] [mpm_winnt:notice] [pid 6128:tid 388] AH00455: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.8 configured -- resuming normal operations
    [Mon Jul 18 16:28:52.742248 2016] [mpm_winnt:notice] [pid 6128:tid 388] AH00456: Apache Lounge VC14 Server built: Dec 9 2015 10:17:39
    [Mon Jul 18 16:28:52.742248 2016] [core:notice] [pid 6128:tid 388] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
    [Mon Jul 18 16:28:52.757857 2016] [mpm_winnt:notice] [pid 6128:tid 388] AH00418: Parent: Created child process 3848
    [Mon Jul 18 16:28:53.554741 2016] [ssl:warn] [pid 3848:tid 408] AH01909: http://www.example.com:443:0 server certificate does NOT include an ID which matches the server name
    [Mon Jul 18 16:28:53.804743 2016] [ssl:warn] [pid 3848:tid 408] AH01909: http://www.example.com:443:0 server certificate does NOT include an ID which matches the server name
    [Mon Jul 18 16:28:53.867263 2016] [mpm_winnt:notice] [pid 3848:tid 408] AH00354: Child: Starting 150 worker threads.

  11. hello sir
    I have tried to run my program .I have installed xampp and notepad ++ properly but when i try to run my program in browser it shows error. pls guide me .

  12. Firefox can't establish a connection to the server at localhost.
    browser is showing this error. please guide me how to fix it .

          1. May be you are not placing the PHP file in the correct location. Reinstalling XAMPP will only work if you place the PHP file in the correct location.

            Also sometimes messaging Software like Skype conflicts with web servers, in that case try uninstalling and then installing XAMPP. Although if you know how to modify port, then this is not necessary, but judging from your comments I think you don't.

Leave a Reply

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