Hello, PHP
What PHP is, how to run it on your computer with XAMPP, and printing your first output with echo.
What is PHP?
PHP is a programming language that runs on the web server. When someone opens a .php page, the server runs the PHP code, builds the HTML, and sends only that HTML to the browser.
That is the big difference from JavaScript, which runs in the visitor's browser. Because PHP runs on the server, it can safely read databases, check passwords and send emails.
| HTML / CSS / JavaScript | PHP | |
|---|---|---|
| Runs in | The visitor's browser | The web server |
| Visitor can see the code? | Yes (View source) | No, only its output |
| Good for | Layout, style, interaction | Forms, logins, databases, emails |
Set up your computer
- Download and install XAMPP from apachefriends.org (it is free).
- Open the XAMPP Control Panel and press Start next to Apache (and MySQL for the database lessons).
- Find the
htdocsfolder inside your XAMPP folder (on Windows:C:\xampp\htdocs). - Make a folder there called
learn-php. Every file you save in it can be opened athttp://localhost/learn-php/.
Your first PHP page
PHP code goes between <?php and ?>. Everything outside those tags is sent to the browser as normal HTML.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My first PHP page</title>
</head>
<body>
<h1><?php echo 'Hello from PHP!'; ?></h1>
<p>Today is <?php echo date('l, j F Y'); ?>.</p>
</body>
</html>
Hello from PHP! Today is Monday, 5 October 2026.
echoprints text into the page.- Every PHP statement ends with a semicolon
;. date('l, j F Y')is a built-in function that returns today's date. PHP has thousands of built-in functions.
Comments
<?php
// A one-line comment
# Also a one-line comment
/* A comment that
spans several lines */
echo 'Comments are ignored by PHP.';
Exercise
Make learn-php/about.php that shows your name in an <h1> and the current year in a paragraph, using echo and date('Y').
<h1><?php echo ''; ?></h1>
<p>The year is </p>
Show a possible solution
<h1><?php echo 'Ada Okafor'; ?></h1>
<p>The year is <?php echo date('Y'); ?>.</p>
Check your understanding
Quick check
Where does PHP code run?
Quick check
How must every PHP statement end?
Quick check
How should you open learn-php/index.php to see it working?