Step by Step Procedure To Run Your First PHP Script on Windows
Welcome to the very first tutorial of PHP, we are going to explore how to run your first PHP script on Windows. This article will help you get started, by running your first ever PHP script on your own computer’s Local Host. For this tutorial, we will be using XAMPP on a Microsoft Windows Operating system.
About XAMPP – How to Run Your First PHP Script on Windows
XAMPP is a very popular and easy-to-install package to get PHP up and running in your PC. By installing this, you will also get a distribution of Apache server, Mysql and Perl.
Apache Server
Well, you need a webserver to run and test your PHP scripts. So, instead of buying hosting from an actual web server, why not to run it in your own computer. For this, we will be using an Apace server locally. It is the most widely used web server in the world and fortunately comes within the distribution of XAMPP.
MySQL
To store the permanent data of a website, databases are used. MySQL is one the famous database management system used today. It stores data in the form of tables, rows and columns. We will be discussing it in further details in upcoming tutorials.
Perl
Perl is a programing language not as famous as PHP. You can call it a substitute for PHP. Since we are discussing PHP here, hence we don’t need to discuss Perl.
Now we are ready to install XAMPP. There are options to get it for Linux and Mac OS as well.
Download Latest Version of XAMPP from here
If you don’t like XAMPP or for any reason or are unable to run it on your PC, you have options to go for the WAMPP for windows as well.
Installation is very simple, you don’t have to change anything just keep every option on its default and keep pressing ‘NEXT’ until Installation is finished. After the easy installation, search for the XAMPP control panel in your PC and run it. This window will pop up. Click on start buttons for Apache and MySQL.
If Installation was successful, the window will change into the screen given below. That indicates that both Apache and MySQL are running fine. You can minimize or close the window if you want. It will continue running in the background.
To verify that everything is working well, go to your browser and type “localhost” if you see the XAMPP starting page that means everything is great.
Your First Script – How to Run Your First PHP Script on Windows
Now it’s time to write your first script in PHP and run it on your browser. To do this,
- First open a text editor e.g. Notepad or Notepad ++ and paste this code in the editor.
<!DOCTYPE html>
<html>
<head>
<title>My First Script</title>
</head>
<body>
<?php echo “Hello World” ?>
</body>
</html>
- It is not required for you to understand this code right now as we will be discussing everything in upcoming tutorials. For now simply copy it and save this file as index.php.
- Now go to C:\xampp\htdocs. This is the folder that will be containing your website files. Create a new folder here and name it whatever you want. We will call it my script.
- Paste your index.php file in this folder. So that the address for index.php will become C:\xampp\htdocs\mysite\index.php. As shown below
Now go to the browser and type the URL localhost/myscript/index.php. And Hurray!!! Here is the outcome for your script.
What Comes Next – How to Run Your First PHP Script on Windows
This whole process was to only get you started. Next time, to change the code in index.php script you will follow this procedure.
- Open the XAMPP control panel and start the apache and MySQL. (if it’s not already running)
- Go to C:\xampp\htdocs\mysite\index.php in your file explorer and open this file in a text editor.
- Now changing this file in the editor and saving it will change the output of the browser.
- Open a browser and write localhost/myscript/index.php and all changes will be visible to you.
- You can refresh the page to get a result of most recent changes in the script.
Let’s make a minor change in the script and instead of “Hello world” let’s output “Hello world!!! I am excited”. We will have to change the line of code like this to get this output.
<!DOCTYPE html>
<html>
<head>
<title>My First Script</title>
</head>
<body>
<?php echo “Hello World!!! I am exited” ?>
</body>
</html>
See, by changing one line of code will change the output. Why don’t you try it by yourself? Modify this line of script with any text you want, save it and refresh the page on browser to see the changes.
Final Words
In the next article we will be discussing all the code above in more details by learning the basics of HTML, so stay tuned.
Hope you enjoyed your first tutorial on How to Run Your First PHP Script on Windows don’t forget to comment and send samples of your first workings using with PHP script.
Also, see:
Part Two: BASICS OF HTML5 ON THE WAY TO PHP LEARNING
Part Three: PHP WORKING WITH DATA TYPES AND VARIABLES
Part Four: IF ELSE STATEMENTS AND ARITHMETIC OPERATIONS IN PHP
Part Five: TUTORIAL ON TYPES OF LOOPS IN PHP – PHP LOOP TYPES
Part Six: INDEXED AND ASSOCIATIVE ARRAYS IN PHP
Part Seven: FUNCTIONS IN PHP
Part Eight: INTRODUCTION TO MYSQL
Part Nine:CONNECTING MYSQL DATABASE PHP
Part Ten: FORMS IN PHP – PHP FORM EXAMPLE WITH DATABASE
Main Image Source : Pixabay
Also See : 7 Best Weapons To Use For Self-Defence In a Post-Apocalyptic World (Top 10) Part 1