PHP Introduction

PHP · Lesson 1 of 50 7 min read Updated

When you log in to a college portal, search for a train on a booking site or post a comment on a blog, a program on a server builds the page you see. PHP is one of the most widely used languages for writing those server programs.

In this lesson you will learn what PHP is, how it fits between the browser and the server, what people build with it, and which version you should learn today.

What is PHP?

PHP is a server-side scripting language. Server-side means the code runs on the web server, not in the visitor's browser. Scripting means you write plain text files that PHP reads and runs directly, with no separate build step.

The name is a recursive acronym: PHP: Hypertext Preprocessor. Rasmus Lerdorf created it in 1994 to track visits to his own home page, and it has grown into a full, general-purpose language. It is free and open source.

A PHP file usually ends in .php. It can contain plain HTML with small pieces of PHP code mixed in. PHP code goes between <?php and ?> tags. The <?= tag is a short way to print a value.

PHP
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Canteen Bill</title>
</head>
<body>
  <h1>Your bill</h1>
  <p>Two samosas and one chai cost ₹<?= 2 * 15 + 12 ?>.</p>
</body>
</html>

The browser never receives the PHP code. It receives only the result:

Output
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Canteen Bill</title>
</head>
<body>
  <h1>Your bill</h1>
  <p>Two samosas and one chai cost ₹42.</p>
</body>
</html>

How PHP works on a web server

Here is what happens when someone opens a PHP page, step by step:

  1. The browser asks the server for a page, for example /result.php.
  2. The web server software (usually Apache or Nginx) sees the .php extension and passes the file to PHP.
  3. PHP runs the code from top to bottom. On the way it may read a database, check a login or do some maths.
  4. PHP produces plain HTML as its output and hands it back to the web server.
  5. The server sends that HTML to the browser, which displays it.

Because the code runs on the server, visitors cannot see your PHP source, your database password or your business rules. This is the key difference from JavaScript in the browser, which you can read about in the JavaScript tutorial.

Runs where?LanguageTypical job
BrowserHTML, CSS, JavaScriptShow the page and react to clicks
ServerPHPBuild the page, handle forms, talk to the database
Database serverSQL (MySQL)Store and search data

PHP is not only for web pages. You can also run a PHP file from the terminal, which is how most examples in this course work. This short script works out a team's run rate:

PHP
<?php
$runs = 186;
$overs = 20;

echo "Run rate: " . round($runs / $overs, 2) . "\n";
Output
Run rate: 9.3

Do not worry about the details yet. You will learn echo, variables and maths in the next few lessons.

What is PHP used for?

PHP is a practical language built for the web. People use it to:

  • Build dynamic pages that change for each visitor, such as a student dashboard.
  • Handle HTML forms: contact forms, registrations, search boxes and payments.
  • Manage logins with sessions and cookies.
  • Store and read data in databases such as MySQL.
  • Create JSON APIs for mobile apps and JavaScript front ends.
  • Read and write files, send emails and generate reports.
  • Run scheduled tasks from the command line.

A lot of well-known software is written in PHP. WordPress, the most popular website platform, is PHP. So are the Laravel and Symfony frameworks, the Moodle learning platform used by many universities, WooCommerce online shops and MediaWiki, the software behind Wikipedia. Learning PHP means you can understand, fix and extend all of these.

PHP today: version 8.5

PHP gets one new feature release every year, usually in November. The current version is PHP 8.5, released on 20 November 2025. This course teaches PHP 8.5, and almost everything also works on PHP 8.4.

Modern PHP is very different from the PHP of 15 years ago. It has types for parameters and return values, a strict mode, enums, match expressions and a fast engine. Many complaints you may hear online come from old code and old tutorials.

VersionYearA few headline features
8.02020match, named arguments, nullsafe ?->
8.12021Enums, readonly properties, strlen(...) callables
8.22022Readonly classes
8.32023Typed class constants, json_validate()
8.42024Property hooks, array_find()
8.52025Pipe operator |>, array_first(), URI extension

Older versions stop receiving security fixes after a few years. Always use a supported version on a live website. The official supported versions page shows the dates.

How this course works

PHP runs on a server, so there is no "Try it" button in this course. Instead, you will install PHP on your own computer in the next lesson and run every example yourself. After each example you will see an Output box that shows exactly what the code prints.

Type the examples by hand rather than copying them. Typing builds memory, and the small mistakes you make teach you how to read error messages.

Common mistakes

  • Double-clicking a .php file. The browser opens it as a plain file and shows the code or downloads it. PHP pages must be opened through a web server, such as http://localhost/. The next lesson shows you how.
  • Thinking PHP runs in the browser. PHP finishes its work before the page reaches the browser. To react to a click without reloading, you need JavaScript.
  • Learning from outdated tutorials. If a tutorial uses mysql_query() or does not escape output, it is more than ten years out of date. The mysql_* functions were removed in PHP 7.0. Use PDO instead, which you will learn in Connecting to MySQL with PDO.

Key points

  • PHP is a free, open-source, server-side scripting language for building web applications.
  • The server runs the PHP code and sends only the resulting HTML to the browser.
  • PHP code lives between <?php and ?>, and <?= prints a value.
  • PHP powers WordPress, Laravel, Symfony, Moodle and much more of the web.
  • PHP 8.5, released on 20 November 2025, is the current version and the one this course teaches.

Exercise

On paper or in a text file, write the five steps that happen when Ananya opens marks.php on her college website. Then write a tiny PHP script (you will run it after the next lesson) that prints your name on one line and the result of 12 * 85 on the next line.

Show solution

The steps: the browser requests marks.php; the web server passes it to PHP; PHP runs the code and may read the marks from a database; PHP outputs HTML; the server sends the HTML to the browser.

PHP
<?php
echo "My name is Ananya\n";
echo 12 * 85 . "\n";
Output
My name is Ananya
1020

The \n inside double quotes starts a new line in the terminal.

Quick Quiz

1. Where does PHP code run?

2. What does the browser receive from a PHP page?

3. Which is the current PHP release in this course?

4. Why should you not double-click a .php file to open it?

Learn PHP with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call