What Are We Doing in This Post?
In Episode 01, we understood what PHP is and why we are learning it. Now it is time to actually get our hands dirty.
By the end of this post, you will have:
- PHP running on your Windows machine
- A local development server set up
- VS Code installed and ready
- Your very first PHP program written and running
Let us get started.
Step 1 — Install XAMPP (PHP + Server in One Package)
On Windows, the easiest way to get PHP running is through a tool called XAMPP.
Here is what XAMPP actually is.
Remember the restaurant analogy from Episode 01? PHP is the kitchen. But a kitchen needs a building to sit inside. That building is a web server — specifically, Apache. XAMPP gives you PHP and Apache together in one installation. One download, one install, everything works.
XAMPP also includes MySQL, which is the database system we will use later in this course.
How to install XAMPP:
Go to this website in your browser: apachefriends.org
Click the big Download button for Windows. The file will be around 150 MB. Once it downloads, open the installer and follow these steps:
Run the installer as Administrator. Right-click the downloaded file and select "Run as administrator."
When the installer asks which components to install, make sure these three are checked: Apache, MySQL, PHP. You can uncheck everything else if you want — FileZilla, Mercury, Tomcat are not needed for this course.
Choose the installation folder. The default is C:\xampp — keep it as is. Do not change it to Program Files because that folder has permission restrictions that can cause problems later.
Click Next and let the installation finish. It takes about two to three minutes.
Step 2 — Start Apache (Your Local Web Server)
After installation, XAMPP will open the XAMPP Control Panel. This is your dashboard for starting and stopping services.
You will see a list of services: Apache, MySQL, FileZilla, Mercury, Tomcat.
Click the Start button next to Apache.
If Apache starts successfully, the row will turn green and you will see port numbers like 80 and 443 appear next to it.
Now open your browser and go to: http://localhost
If you see the XAMPP welcome page, congratulations — your local web server is running. Your computer is now acting like a mini web server, just like the ones that host real websites on the internet.
What is localhost?
Localhost is just a name that means "this computer." When you type http://localhost in your browser, you are visiting a website that is running on your own machine — not on the internet. Only you can see it. This is your safe development environment.
Step 3 — Install VS Code
If you already installed VS Code after Episode 01, skip this step.
Go to code.visualstudio.com and download the Windows installer. Run it and follow the default installation steps.
After installing, open VS Code. It will look empty right now — that is fine.
One extension to install right now:
Inside VS Code, click the Extensions icon on the left sidebar (it looks like four squares). Search for PHP Intelephense and install it. This extension gives you autocomplete, error highlighting, and code hints for PHP. It will make your life much easier.
Step 4 — Find Your PHP Folder
When XAMPP installs, it creates a special folder on your computer:
C:\xampp\htdocs
This folder is the root of your local web server. Any file you put inside this folder can be accessed through your browser using localhost.
Think of it this way. If a real website's files live on a server somewhere in the world, your htdocs folder is that server — but it lives on your own computer.
Open File Explorer and navigate to C:\xampp\htdocs. You will see some files already there — those are XAMPP's default files. Leave them alone.
Create a new folder inside htdocs. Name it: phplearning
This is where all your practice files for this course will live.
Step 5 — Write Your First PHP Program
This is the moment. Let us write actual PHP code.
Open VS Code. Go to File, then Open Folder, and open the phplearning folder you just created at C:\xampp\htdocs\phplearning.
Create a new file inside this folder. Name it: index.php
Now type this code exactly as shown:
<?php
echo "Hello, World! My PHP is working.";
?>
Save the file. Now open your browser and go to:
http://localhost/phplearning/index.php
You should see this text on the screen:
Hello, World! My PHP is working.
That is it. That is PHP running on your computer. You just wrote and executed your first PHP program.
Understanding What You Just Wrote
Let us break down those three lines.
<?php
This is the PHP opening tag. It tells the server: "Hey, everything from here onwards is PHP code. Process it."
echo "Hello, World! My PHP is working.";
echo is a PHP command that means "print this to the screen." Whatever you put inside the quotes gets displayed in the browser. The semicolon at the end is mandatory in PHP — every statement must end with a semicolon.
?>
This is the PHP closing tag. It tells the server: "PHP code ends here."
Every PHP file follows this basic structure. Opening tag, your code, closing tag.
A Real World Analogy for How PHP Works
Here is exactly what happened when you visited that URL in your browser.
You typed http://localhost/phplearning/index.php and pressed Enter.
Your browser sent a request to your local Apache web server — the one running through XAMPP.
Apache looked at the file you requested. It saw the .php extension and said: "This is a PHP file. I need to hand it to the PHP engine."
The PHP engine read your code, executed the echo statement, and produced plain HTML output: Hello, World! My PHP is working.
Apache sent that HTML back to your browser.
Your browser displayed it.
You never saw the PHP code. The browser only ever sees the final HTML output. This is what server-side means — the processing happens on the server, not in the browser.
Let Us Try a Few More Things
Now that the basics are working, let us explore a little.
Experiment 1 — PHP and HTML together
Replace everything in your index.php file with this:
<!DOCTYPE html> <html> <head> <title>My First PHP Page</title> </head> <body>
<h1><?php echo "Welcome to my PHP page!"; ?></h1> <p>Today's date is: <?php echo date("d F Y"); ?></p>
</body> </html>
Save it and refresh your browser at http://localhost/phplearning/index.php
You will see a heading and today's actual date displayed dynamically. PHP calculated the current date for you automatically.
This is the power of PHP mixed with HTML. Static HTML just shows fixed content. PHP inside HTML makes it dynamic — the content can change based on logic, data, or time.
Experiment 2 — PHP doing math
Add this line inside your PHP section:
<?php echo 10 + 25; ?>
PHP will calculate 10 + 25 and display 35 in the browser. The browser does not see the math — it only sees the result. PHP did the calculation on the server.
Common Errors Beginners Face (And How to Fix Them)
Before we close this episode, let us talk about errors you might run into.
Apache does not start — port conflict
If Apache shows red in the XAMPP Control Panel and does not start, it usually means another program is already using port 80. This is often Skype or IIS (Windows web server).
Fix: In the XAMPP Control Panel, click Config next to Apache, then click httpd.conf. Find the line that says Listen 80 and change it to Listen 8080. Save the file and restart Apache. Now access your site at http://localhost:8080 instead of http://localhost.
Page shows PHP code instead of output
If your browser shows the raw PHP code instead of running it, it means you opened the file directly from File Explorer instead of through localhost. Always access PHP files through http://localhost/... — never by double-clicking the file.
Blank white page
This usually means there is a syntax error in your PHP code — a missing semicolon, an unclosed quote, or a typo. Check your code carefully. We will learn about proper error reporting in the next episode.
What Did We Learn in This Post?
Let us quickly recap everything covered.
You installed XAMPP, which gives you Apache (web server), PHP, and MySQL in one package.
You started Apache and confirmed your local server is working by visiting http://localhost.
You installed VS Code with the PHP Intelephense extension for a proper coding environment.
You learned that C:\xampp\htdocs is your local server's root folder — files here are accessible via http://localhost.
You wrote your first PHP program using the echo command and understood how PHP runs on the server and sends HTML to the browser.
You mixed PHP with HTML to create dynamic content, including displaying today's date automatically.
What is Coming in Episode 03?
Now that your environment is set up, we go into Core PHP properly.
Episode 03 covers: variables, data types, and how PHP stores and works with information. We will build real examples — like storing a user's name and displaying a personalized greeting — so every concept has a practical purpose.
See you in the next one.
Next Episode: PHP Variables, Data Types, and How PHP Thinks About Data
This is Episode 02 of the PHP and Laravel — Zero to Hero series. Follow the blog so you do not miss an episode.