Setting up the PHP/MySql XAMPP Environment on Windows

We will install the XAMPP bundled PHP/MySql system. Installing the XAMPP (or similar) bundle is much easier than installing all the components separately.

Pre-Requisite: Atom, NotePad++ or some other Programming Editor

https://atom.io/

Installing XAMPP

There is a screen cast of this process below on YouTube. You can watch the screen cast and follow along to complete the tasks. There are notes below the YouTube video as well. You may want to print this page to have the notes as you follow the steps in the video.

Installation Notes

Download the installation package from:

     https://www.apachefriends.org/index.html
I choose the "Installer" (i.e. neither the ZIP nor 7zip) installation package. Download the package to your desktop and once the download is complete, run the installer, and go through the installation steps. Make sure you are doing this on an administrator account.

Starting the XAMPP Control Panel Application

If you installed XAMPP in the default location, you can find it at:

    C:\XAMPP\xampp-control.exe
You can pin this to your task bar once it starts to make it easier to launch.

You will need to Start both the Apache and MySql service. When you press Start, you may be prompted for some firewall settings or other trust dialog boxes. Make sure to say 'yes' to these trust boxes. Generally you will only see these trust dialogs once.

Once you get two little green "Running" indicators (Apache and MySql) in the XAMPP control panel, you can press the "Admin..." button next to Apache to launch the XAMPP user interface. Note that the "Admin..." button next to MySql seems not to function. Don't worry about that. You could also bring up the XAMPP start screen by navigating your web browser to:

     http://localhost/
It should initially start with an XAMPP splash screen so you can select your language and then proceed to the XAMPP main screen with an orange navigation bar along the right side.

Your First PHP Program

Open a text editor (i.e. Atom) and put the following text in the file putting your own name or something elese uniquely identifying in instead of mine:

<h1>Hello from Dr. Chuck's HTML Page</h1>
We will start simple and since PHP is simply an extension of HTML, our first program is just an HTML file.

Save this file as:

    C:\xampp\htdocs\first\index.php
Create the folder first under the htdocs folder when you save the file. If you get a permissions error while creating the folder or saving the file it likely means that you either are not running as the administrator.

Once you have saved this file, navigate your browser to:

    http://localhost/first/index.php

And you should see your web page in your browser.

Once that works, lets add a little PHP to our HTML. Change your file to be as follows and re-save:

<h1>Hello from Dr. Chuck's HTML Page</h1>
<p>
<?php
   echo "Hi there.\n";
   $answer = 6 * 7;
   echo "The answer is $answer, what was the question again?\n";
?>
</p>
<p>Yes another paragraph.</p>
After you save, press "Refresh" in your browser and it should appear as follows:

Congratulations, you have written your first PHP program.

Displaying Syntax Errors

XAMPP usually comes configured by default to display errors when you make a mistake in your PHP code. This is an appropriate setting cwwhile developingdevelopers.

To verify this, go into the XAMPP control panel and select Config and then php.ini. This will being up a NotePad with the PHP configuration. Scroll down to verify that:

display_errors=On

If it is Off change it to On and then go back to the XAMPP Control Panel and stop and then restart the Apahce server. Then go back to Admin page and check the PHPInfo page to make sure that display_errors is indeed On.