Wednesday, December 7, 2016

Installing, Configuring, and Developing PHP on Localhost with XAMPP

Share it Please


This article explains the installation and configuration process of the XAMPP Apache distribution. First of all grab a copy of XAMPP installer by clicking here and picking your operating system.

NOTE: this tutorial is intended for windows users, 'Linux' and 'Mac' should have a very similar procedure though.

Installation Requirements:
    XAMPP is a small and light Apache distribution containing the most common web development technologies in a single package making it the ideal tool for beginners developing and testing applications in PHP and MySQL.

  • approximately 17 MB for the self-extracting ZIP
  • at least 118 MB after it has been extracted
Once downloaded, run the installer and follow through the instructions.

NOTE: if you get a warning regarding user account control, ignore it. Press 'OK' and continue ahead to installation making sure that you do not set the installation directory to windows system folders that would need write permissions.



when prompted for component selection, it is recommended to select all. Although for now we just need Apache, MySQL, PHP, phpMyAdmin. If you want you can go ahead and just select them and continue with installation clicking next. Windows Security Alert might ask for firewall permissions, check both private and public networks and click Allow Access. Once installation is done, click finish and XAMPP should run automatically. Pick your language and you are ready to go.

XAMPP Control Panel:

Once installed and ran, XAMPP control panel looks like:


Start 'Apache' and 'MySQL' and we are ready to write our very first PHP script and run it.

NOTE: if you get the following error when trying to start Apache:

Port 80 in use by "c:\program files (x86)\skype\phone\skype.exe"!

it's because SKYPE uses the same port that Apache tries to use. For now just close SKYPE and start Apache, a guide to fix that will be posted soon!

Once you start Apache and MySQL, open your browser and type in the URL 'localhost' and click go. If you followed the steps so far, you should see the 'XAMPP Welcome Page'. If you didn't, please post in the comments section if you had any problems or errors. I will try my best to reach to every single question.

Now back to the matter at hand, running our very first PHP script. In order for Apache to run PHP scripts, the script must be in the root directory of the web. In our case, its in the following directory:

C:\xampp\htdocs

NOTE: if you changed the installation directory during your installation, it will be 
youInstalledDirectory\htdocs

Now open up a text editor, basically any text editor works including windows notepad, but if you are planing to bigger scale app's, I would recommend you to use Sublime Text. Paste the following code in the text editor and save the file as 'hello.php'.

<?php echo "Hello PHP";  ?>

save it in the apache web dir C:\xampp\htdocs . Congratulations!  you just wrote your very first PHP script.

Now browse over to localhost/hello.php and you should see your script print out "Hello PHP" for you.

In the next part of the tutorial, we will make a small app which would further take us into the MySQL part. If you have any questions so far, please post it in the comments section.





No comments:

Post a Comment

Blogroll

About