PHP Tutorial

This PHP tutorial teaches you modern PHP 8.3 from the very first line of code up to object-oriented programming and database access. PHP is a server-side scripting language: your PHP code runs on the web server, builds a page (usually HTML), and sends the finished result to the browser.

PHP powers a huge share of the web, including WordPress, Laravel applications, Drupal, and countless custom business systems. It is easy to start with, cheap to host, and has matured into a fast, typed, well-designed language.

What Is PHP?

PHP stands for "PHP: Hypertext Preprocessor". A PHP file can contain plain HTML plus PHP code inside <?php ... ?> tags. When someone requests the page, the server runs the PHP parts and replaces them with their output. The visitor never sees your PHP source, only the generated HTML.

  • Runs on the server, not in the browser
  • Free and open source, works on Linux, Windows and macOS
  • Talks to databases like MySQL, MariaDB, PostgreSQL and SQLite
  • Handles forms, files, sessions, cookies, email and APIs
  • Is the foundation of frameworks such as Laravel and Symfony

Your First PHP Example

Here is a tiny PHP script. The echo statement sends text to the output. Every PHP statement ends with a semicolon.

<?php
$name = "World";
echo "Hello, $name!\n";
echo "PHP version: " . PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;
Hello, World!
PHP version: 8.3

PHP Mixed With HTML

The classic way to use PHP is inside an HTML page. Only the part between the PHP tags is executed; everything else is sent as-is. The short echo tag <?= ... ?> is a handy shortcut for printing a value.

<!DOCTYPE html>
<html>
<body>
  <h1>Welcome</h1>
  <p>Today is <?= date('l') ?>.</p>
</body>
</html>
<h1>Welcome</h1>
<p>Today is Friday.</p>

Why Learn PHP in 2026?

PHP is still one of the most practical languages for building websites. Hosting is everywhere, the job market for WordPress and Laravel developers is large, and PHP 8 brought big improvements: a JIT compiler, union types, enums, readonly properties, match expressions and named arguments.

If you want to build real web applications quickly, PHP plus Laravel is a very productive combination.

What This PHP Tutorial Covers

  • Installing PHP and running scripts
  • Syntax, variables, data types and strings
  • Operators, conditions and loops
  • Functions and arrays
  • Handling HTML forms safely
  • Sessions, cookies and files
  • Object-oriented PHP and exceptions
  • Connecting to MySQL with PDO
  • Practice examples and exercises

Frequently asked questions

Is PHP still worth learning?

Yes. PHP runs a large portion of all websites, including WordPress, and frameworks like Laravel are widely used in companies. Modern PHP 8 is fast and pleasant to write.

Is PHP frontend or backend?

PHP is a backend (server-side) language. It runs on the server and produces HTML, JSON or other output that the browser receives.

How long does it take to learn PHP?

With basic HTML knowledge you can write useful PHP scripts within a couple of weeks. Becoming comfortable with OOP, databases and a framework usually takes a few months of practice.

Do I need to know HTML before PHP?

It helps a lot. Most PHP output is HTML, so knowing basic tags and forms makes PHP much easier to understand.