Hello, PHP

Lesson 1 of 15 11 min read Free lesson

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 / JavaScriptPHP
Runs inThe visitor's browserThe web server
Visitor can see the code?Yes (View source)No, only its output
Good forLayout, style, interactionForms, logins, databases, emails

Set up your computer

  1. Download and install XAMPP from apachefriends.org (it is free).
  2. Open the XAMPP Control Panel and press Start next to Apache (and MySQL for the database lessons).
  3. Find the htdocs folder inside your XAMPP folder (on Windows: C:\xampp\htdocs).
  4. Make a folder there called learn-php. Every file you save in it can be opened at http://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.

learn-php/index.php
<!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>
Output
Hello from PHP!
Today is Monday, 5 October 2026.
  • echo prints 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
<?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').

Starting code
<h1><?php echo ''; ?></h1>
<p>The year is </p>
Show a possible solution
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?

Hi there! đź‘‹ Have a question about the courses or joining the class? Ask me.