ScopeTreasure.

Back

PHP Courses · Lesson PH.1

What Is PHP? + Setup

CODE SCOPE PHP SERIESLESSON PH.1 OF PH.1–PH.12

PHP is the language that runs on the server and builds the page before the browser ever sees it — learn what it is, why Laravel needs it, and run your first page with XAMPP.

Free PDF of this lesson — save it, print it, revise offline. This lesson's own video is not on the channel yet — the Watch button opens the Code Scope channel, where the rest of the series lives.

Introduction

When you open a website, the page you see is HTML. But somebody had to build that HTML — fetch the student's name from the database, check the password, decide what to show. On most of the web, that somebody is PHP.

PHP is a server-side language. That means PHP code never runs in your browser. It runs on the server: the browser asks for a page, PHP thinks, builds plain HTML, and sends only the finished HTML back. Your browser never sees the PHP code at all — and that is why passwords and database details stay safe.

PHP powers a huge part of the web — WordPress, Facebook's early days, and Laravel, the framework you will meet in the next phase. Learn PHP first and Laravel becomes easy, because Laravel is written in PHP.

(Roman Urdu: PHP server par chalta hai — browser ko sirf tayyar HTML milta hai, PHP code kabhi nazar nahi aata. Isi liye Laravel se pehle PHP seekhna zaroori hai.)

To run PHP on your own computer you need a local server. The easy way is XAMPP — one free install that gives you Apache (the server), MySQL (the database) and PHP together. You put your files in XAMPP's htdocs folder and open them at http://localhost/your-file.php.

Key points

  • PHP stands for "PHP: Hypertext Preprocessor" — a language that prepares web pages before they reach the browser.
  • Server-side means the code runs on the server, not in the browser. The browser only ever receives finished HTML.
  • A .php file can hold HTML and PHP together. PHP parts sit between <?php and ?> tags; everything outside the tags is plain HTML.
  • echo prints text into the page. echo "Hello"; sends the word Hello into the HTML.
  • XAMPP is the beginner's local server. Install it once and you get Apache + MySQL + PHP in one package.
  • Your files live in htdocs. On Windows that is usually C:\xampp\htdocs; on Mac it is /Applications/XAMPP/htdocs.
  • Open PHP pages through http://localhost/..., never by double-clicking. Double-clicking opens the file, not the server — and PHP will not run.
  • PHP is free and open source. No licence, no payment, and it runs on almost every web host in the world.
  • PHP is Laravel's base language. Every Laravel file you will write later is a PHP file first.

Examples

Example 1 — Your first PHP page

Save this as hello.php inside htdocs, start Apache in the XAMPP control panel, then open http://localhost/hello.php:

<?php
echo "Hello, PHP!";
?>

What you will get:

Hello, PHP!

The browser shows only the words. Right-click the page and choose View Source — you will see Hello, PHP! and no PHP code at all. The server already ran it.

Example 2 — PHP inside HTML

A PHP file is mostly a normal HTML page with small PHP islands inside it:

<!DOCTYPE html>
<html>
<body>
<h1>Welcome</h1>
<p>Today is <?php echo date("l"); ?>.</p>
</body>
</html>

What you will get:

Welcome
Today is Tuesday.

date("l") is a built-in PHP function that gives the full name of today's day. The day changes by itself — no editing needed.

Example 3 — PHP does the maths before the page loads

<?php
$price = 250;
$qty = 3;
$total = $price * $qty;
echo "Total: ";
echo $total;
?>

What you will get:

Total: 750

The browser never sees $price * $qty. It only receives Total: 750. That is the whole idea of server-side code.

Example 4 — Checking that PHP is alive

A one-line file that proves your server works — every beginner should run this first:

<?php
phpinfo();
?>

What you will get:

A long page showing your PHP version and every setting.

If you see that page, XAMPP and PHP are running. If you see the raw code instead, Apache is not running — start it in the XAMPP control panel.

Example 5 — A comment the browser never sees

<?php
// This line is a note for humans only. PHP skips it.
echo "Hi";
/* This is a longer note.
   It can span many lines. */
echo " there";
?>

What you will get:

Hi there

Comments explain your code to the next person who reads it. The browser never receives them.

Quick recap

  • PHP runs on the server and sends finished HTML to the browser.
  • PHP code lives between <?php and ?> inside a .php file.
  • echo prints text into the page; date("l") gives today's day name.
  • XAMPP gives you Apache + MySQL + PHP; files go in htdocs.
  • Open pages through http://localhost/..., never by double-clicking.
  • PHP is free, and it is the language Laravel is built on.

Common mistakes

  1. Double-clicking the .php file — the browser shows raw code or downloads the file. Fix: start Apache, then open http://localhost/your-file.php.
  2. Forgetting to start Apache in XAMPP — the browser says the site cannot be reached. Fix: open the XAMPP control panel and press Start next to Apache.
  3. Saving the file outside htdocs — http://localhost cannot see it. Fix: save every PHP file inside the htdocs folder.
  4. Writing PHP in a .html file — the server treats it as plain HTML and the code shows on the page. Fix: the file must end in .php.
  5. Forgetting the closing ?> when HTML follows — PHP swallows the HTML as code and errors. Fix: close the tag before the HTML starts (a file that is pure PHP may skip the closing tag).
  6. Expecting the browser to show PHP errors nicely — a blank white page usually means a PHP error with display turned off. Fix: check the XAMPP Apache error log, or add error_reporting(E_ALL); at the top while learning.

Practice

  1. Install XAMPP, start Apache, and open http://localhost — write down what you see.
  2. Create htdocs/hello.php with echo "Hello, PHP!"; and open it at http://localhost/hello.php.
  3. View Source on that page and confirm no PHP code is visible to the browser.
  4. Make a page that prints today's day with date("l") and the year with date("Y").
  5. Create htdocs/info.php with phpinfo(); and find your PHP version number on the page.
  6. Deliberately open hello.php by double-clicking it in the folder — write down, in one line, what happens and why.
  7. Write a page that echoes your name inside an <h1> and a sentence about yourself inside a <p>.

Practice quiz

Practice questions — try them, then check your answers in the interactive quiz on the full lesson page.

1. Where does PHP code run?

  • In the browser, like JavaScript
  • On the server: the browser only ever receives finished HTML
  • Inside the HTML file, by the visitor
  • In the database

2. What does XAMPP give you in one install?

  • Only a text editor
  • Apache (the server) + MySQL (the database) + PHP
  • Only a database
  • A finished website

3. How do you open a PHP page on your own computer?

  • By double-clicking the .php file
  • Through http://localhost/your-file.php with Apache running
  • By opening it in Notepad
  • By emailing it to yourself

The interactive quiz with instant green/red answers lives on the full lesson page.