
Last Updated: January 2026
Hey there! So you want to learn PHP programming but have no idea where to start? I’ve been exactly where you are right now – staring at code that looks like gibberish, wondering if I’ll ever figure this out.
Spoiler alert: I did. And you will too.
Today I’m going to walk you through how to start learning PHP from the absolute basics. No confusing jargon. No assuming you already know stuff. Just a straightforward, step-by-step guide to help you write your first PHP code and understand what the heck you’re actually doing.
What is PHP (And Why Should You Care)?
Before we dive into coding, let me quickly explain what PHP actually is.
PHP (which stands for PHP: Hypertext Preprocessor – yes, it’s a recursive acronym) is a server-side scripting language that powers over 75% of websites on the internet. If you’ve ever used WordPress, Facebook, or Wikipedia, you’ve used PHP without even knowing it.
Here’s why I recommend PHP as your first programming language:
It’s beginner-friendly. Seriously, if you can write HTML, you can learn PHP. The syntax is straightforward and forgiving, unlike some languages that throw errors at you for breathing wrong.
You can see results immediately. Unlike some programming languages where you spend weeks on theory, with PHP you can build actual working websites within days. That instant gratification keeps you motivated.
It’s in massive demand. PHP developers are constantly needed because so many websites run on PHP. WordPress alone powers 40% of the entire internet, and it’s built on PHP.
It’s completely free. No expensive licenses, no proprietary software. Everything you need to learn PHP programming is free and open-source.
Step 1: Set Up Your PHP Development Environment
Before you can start coding, you need somewhere to actually write and run PHP code. Don’t worry – this is easier than it sounds.
Option 1: Install XAMPP (My Recommendation for Beginners)
XAMPP is a free, all-in-one package that includes everything you need – Apache web server, PHP, and MySQL database. It works on Windows, Mac, and Linux.
Here’s how to install it:
- Download XAMPP from the official website
- Run the installer (just keep clicking “Next” – the default settings work fine)
- Once installed, open the XAMPP Control Panel
- Click “Start” next to Apache
That’s it. You now have a working PHP development environment on your computer.
Option 2: Use an Online PHP Editor
If you don’t want to install anything yet, you can use free online PHP editors like:
- PHP Sandbox
- OnlinePHP
- 3v4l.org
These let you write and run PHP code directly in your browser. Perfect for practice, though you’ll eventually want a local setup for real projects.
Step 2: Write Your First PHP Script (Hello World!)
Alright, let’s write some actual code. This is where PHP starts to feel real instead of just abstract concepts.
Open your favorite text editor (I recommend this powerful editor or Sublime Text) and create a new file called hello.php.
Save it in your XAMPP’s htdocs folder (usually C:\xampp\htdocs\ on Windows or /Applications/XAMPP/htdocs/ on Mac).
Now type this code:
php
<?php
echo "Hello World! I'm learning PHP!";
?>
Save the file, open your web browser, and go to http://localhost/hello.php.
You should see: Hello World! I’m learning PHP!
Congratulations! You just wrote your first PHP program. Let me explain what just happened:
<?phptells the server “hey, PHP code is starting here”echois a PHP command that displays text- The text goes in quotes
;ends each PHP statement (like a period ends a sentence)?>tells the server “PHP code is done”
Step 3: Understanding PHP Syntax Basics
Now that you’ve written your first script, let’s break down the basic PHP syntax you need to know.
Variables (Storing Information)
Variables are like labeled boxes where you store information. In PHP, all variables start with a dollar sign $.
php
<?php
$name = "Michael";
$age = 25;
$price = 19.99;
echo "My name is " . $name . " and I'm " . $age . " years old.";
?>
Variables can store text (strings), numbers (integers), decimals (floats), and more. The cool part? PHP automatically figures out what type of data you’re storing – you don’t have to tell it.
Comments (Notes to Yourself)
Comments are notes in your code that PHP ignores. They’re essential for documenting what your code does:
php
<?php
// This is a single-line comment
/* This is a
multi-line comment
that spans multiple lines */
$total = 100; // Comments can go at the end of lines too
?>
Trust me, when you come back to your code weeks later, you’ll thank yourself for writing clear comments.
Step 4: Working with Data Types
PHP handles different types of data. Here are the main ones you’ll use constantly:
Strings (Text)
php
<?php
$greeting = "Hello there!";
$message = 'Single quotes work too';
?>
Integers (Whole Numbers)
php
<?php
$visitors = 150;
$downloads = 5000;
?>
Floats (Decimal Numbers)
php
<?php
$price = 29.99;
$temperature = 98.6;
?>
Booleans (True or False)
php
<?php
$is_logged_in = true;
$has_permission = false;
?>
Understanding data types helps you know what you can do with your variables. You can’t add text to numbers (well, you can, but weird things happen).
Step 5: Control Structures (Making Decisions)
This is where your code starts getting smart. Control structures let your PHP programs make decisions.
If Statements
php
<?php
$age = 20;
if ($age >= 18) {
echo "You can vote!";
} else {
echo "Sorry, you're too young to vote.";
}
?>
Loops (Doing Things Repeatedly)
Instead of writing the same code 100 times, use loops:
php
<?php
// Count from 1 to 10
for ($i = 1; $i <= 10; $i++) {
echo "Number: " . $i . "<br>";
}
?>
Loops are incredibly powerful. They let you process lists of data, repeat actions, and automate tasks that would take forever manually.
Step 6: Functions (Reusable Code Blocks)
Functions are like recipes – you define them once, then use them whenever you need them.
php
<?php
function greetUser($name) {
return "Welcome back, " . $name . "!";
}
echo greetUser("Michael"); // Outputs: Welcome back, Michael!
echo greetUser("Sarah"); // Outputs: Welcome back, Sarah!
?>
Instead of rewriting the same code everywhere, you call the function. This makes your code cleaner and easier to maintain.
Step 7: Arrays (Storing Multiple Values)
Arrays let you store multiple related values in a single variable:
php
<?php
$fruits = array("Apple", "Banana", "Orange");
echo $fruits[0]; // Outputs: Apple
echo $fruits[1]; // Outputs: Banana
?>
Arrays are essential for working with lists of data – products, users, blog posts, whatever your website needs to handle.
Step 8: Combining PHP with HTML
Here’s where PHP really shines – you can embed it directly into HTML to create dynamic web pages:
php
<!DOCTYPE html>
<html>
<head>
<title>My Dynamic Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<?php
$current_time = date("h:i A");
echo "<p>The current time is: " . $current_time . "</p>";
?>
<p>This is regular HTML text</p>
</body>
</html>
This is how you build real websites – combining the structure of HTML with the power of PHP to make things dynamic and interactive.
Your Next Steps in Learning PHP
You’ve now covered the absolute basics of PHP programming. But this is just the beginning.
Here’s what to learn next:
1. Forms and User Input Learn how to collect information from users through HTML forms and process it with PHP. This is crucial for contact forms, login systems, and any interactive website.
2. Working with Databases Learn to connect PHP to MySQL databases [AFFILIATE LINK: MySQL Tutorial Book] to store and retrieve information. This is how you build blogs, user accounts, ecommerce sites – anything that needs to remember information.
3. Sessions and Cookies Understand how to track users across multiple pages and keep them logged in.
4. Object-Oriented PHP Learn a more advanced way of structuring your PHP code using classes and objects.
Resources to Continue Learning PHP
Free Resources:
- PHP.net Official Documentation – The official manual
- W3Schools PHP Tutorial – Great for quick reference
- PHP: The Right Way – Best practices guide
Paid Courses (Worth It):
- Udemy PHP Course – Comprehensive video course
- Codecademy – Interactive learning
- PHP Programming Books Bundle – In-depth textbooks
Development Tools:
- Visual Studio Code – Best free code editor
- PHPStorm – Professional PHP IDE with advanced features
- Sublime Text – Fast, lightweight editor
The Bottom Line
Learning PHP programming doesn’t have to be overwhelming. Start with these basics, practice every single day (even if it’s just 15 minutes), and build small projects that interest you.
I started exactly where you are now. I wrote terrible code. I made mistakes. I got frustrated and almost quit.
But I kept going, and eventually things clicked. Now I build websites and web applications professionally, and it all started with learning these PHP basics.
You can do this. Write that Hello World script. Experiment. Break things. That’s how you learn.
Ready to continue your PHP journey? Set up your development environment today and write your first script. The sooner you start, the sooner you’ll be building real websites with PHP.
Got questions? Drop them in the comments below. I read every single one and I’m here to help fellow beginners learn PHP programming!
