Lesson 1 of 24
What PHP is
PHP is a language for building websites on the server. When you visit a page, PHP runs on the web server, builds the HTML, and sends the finished page to your browser. It powers a huge share of the web — WordPress, much of Facebook's origins, Wikipedia, and countless business sites all run on PHP. It's a practical, in-demand skill for building real, database-backed websites.
Server-side vs browser
You've likely seen JavaScript, which runs in the browser (on the visitor's computer). PHP is different — it runs on the server (the computer that hosts the website), before anything reaches the browser:
- A visitor requests a page (e.g.
profile.php). - The server runs the PHP code — which can read a database, check who's logged in, do calculations.
- PHP produces HTML, which the server sends to the browser.
- The browser just displays that HTML — it never sees the PHP.
This is why PHP is perfect for things that must happen securely on the server: talking to a database, handling passwords, processing form submissions, showing different content per user. The browser only ever gets the final HTML.
PHP mixes into HTML
PHP's original superpower is that it embeds inside HTML. You write normal HTML, then drop into PHP wherever you need dynamic content:
<h1>Welcome</h1>
<p>The year is <?php echo date("Y"); ?>.</p>
<p>2 + 2 = <?php echo 2 + 2; ?></p>
The <?php ... ?> tags switch into PHP. The server runs that code and replaces it with the result, so the browser receives plain HTML:
<h1>Welcome</h1>
<p>The year is 2025.</p>
<p>2 + 2 = 4</p>
This blend of HTML and logic is how PHP builds dynamic pages — HTML for structure, PHP for the parts that change.
What PHP is used for
- Dynamic pages — content that changes per user, per time, per database contents.
- Forms — receiving and processing what users submit (contact forms, sign-ups, searches).
- Databases — reading and writing data (users, products, posts) to power the site.
- Whole applications and frameworks — WordPress (which runs a huge fraction of all websites) is PHP; Laravel is a hugely popular PHP framework for building serious apps.
If you want to build websites that remember things and respond to users — not just static pages — a server language like PHP is what you need, and it's one of the most widely used.
How PHP runs
PHP files end in .php and run on a server with PHP installed. In development you run a local server (PHP has a built-in one: php -S localhost:8000), then visit http://localhost:8000/your-file.php in a browser to see the result. In production, a web host runs PHP for you. Throughout this course, picture your PHP code running on the server and producing HTML for the browser.
The mistake beginners make
Thinking PHP runs in the browser like JavaScript — it doesn't; it runs on the server and produces HTML. This is the key mental model: the browser never sees your PHP, only its output. Also, expecting PHP to update a page after it loads (that's JavaScript's job, in the browser) — PHP runs once, on the server, to build the page. Keep the server-side model clear and PHP makes sense.
Your turn
Predict what HTML the browser receives from this:
<h2>My Page</h2>
<p>Next year is <?php echo date("Y") + 1; ?>.</p>
<p>Total: <?php echo 10 * 5; ?></p>
Your turn
- Understand the model: PHP runs on the SERVER, builds HTML, and sends it to the browser.
- See how PHP embeds in HTML with tags, replaced by its output.
- Know PHP is for dynamic, database-backed sites — the browser only ever sees the resulting HTML.
Key points
- PHP runs on the SERVER, builds HTML, and sends the finished page to the browser (which never sees the PHP).
- It embeds in HTML with tags — HTML for structure, PHP for the parts that change.
- It's for dynamic pages, forms, and databases — sites that remember things and respond to users.
- PHP powers a huge share of the web (WordPress, Laravel) — a practical, in-demand skill.
Q&A · 0
Enrol to ask questions and join the discussion.
No questions yet — be the first to ask.