PHP Tutorial

PHP (Hypertext Preprocessor) is a server-side scripting language designed for the web. You embed PHP inside HTML, the server executes the PHP code, and the browser receives pure HTML/CSS/JS.

Tip: PHP powers content systems like WordPress and is great for forms, logins, REST APIs, and dashboards.

Quick Facts

File Extension.php
Runs OnServer (Apache/Nginx/IIS) with PHP engine
OutputsHTML/CSS/JavaScript (browser can’t see PHP code)
Common DBsMySQL/MariaDB, PostgreSQL, SQLite
Use CasesForms, sessions, authentication, CMS, e-commerce, APIs

How PHP Works

[Browser] --requests--> [Web Server + PHP] --returns HTML--> [Browser renders page]

First PHP Example

<?php
  // Print Hello World
  echo "Hello, World!";
?>

Embedding PHP inside HTML

<!DOCTYPE html>
<html>
<body>
  <h3>Server Time</h3>
  <p>
  <?php echo date("Y-m-d H:i:s"); ?>
  </p>
</body>
</html>
Note: Save files as .php and run them through a server (XAMPP/WAMP/LAMP) — opening directly in the browser won’t execute PHP.

Prerequisite

Before learning PHP, you should know basic HTML, CSS, and JavaScript.

  • HTML – structure of a web page
  • CSS – presentation and layout
  • JavaScript – client-side interactivity

If you want to study these subjects first, visit our Home page for the tutorials.

Why Learn PHP?

BenefitWhat it means for you
Easy to startSimple syntax, embed in HTML, quick results
Huge ecosystemFrameworks (Laravel, CodeIgniter), CMS (WordPress)
Database friendlyConnects easily to MySQL, PostgreSQL, SQLite
Great for backendAuthentication, sessions, REST APIs, admin panels
Next steps: Move to Syntax & Comments to learn tags, statements, and printing values.