0% complete

PHP Introduction · Lesson 1 of 7

What is PHP?

Understand what PHP does and how it works with a web server.

Lesson

PHP is a general-purpose scripting language commonly used on web servers. A PHP program can build a response from request data, application logic, and a database. How a PHP page reaches a browser 1. A browser requests a URL from a web server. 2. The web server passes the PHP file to the PHP runtime. 3. PHP runs on the server and produces a response, often HTML or JSON. 4. The server sends that response to the browser. The browser does not receive the PHP source code. PHP can also power command-line tools, scheduled jobs, and APIs. A useful distinction is that PHP is the language and runtime; a framework such as Laravel is an optional toolkit built with PHP. Try it Save a file ending in .php, run it through a PHP-enabled server, and compare the page source in your browser with the PHP file on disk. Further guidance For every setup lesson, verify which PHP version and extensions are active in the same environment that runs the project. Keep a small reproducible script, use the command-line version output to diagnose configuration problems, and distinguish local development tools from production services. Practice task: Create a fresh example for What is PHP?. Predict the result before running it, then change one input and explain why the result changes. Test a normal case and one boundary or invalid case where it applies. Compare your output with the example and note one rule you would use in a real project.

Code examples

Generate a response with PHP
PHP
$pageTitle = 'PHP runs on the server';
echo $pageTitle;
Expected output
PHP runs on the server

Key points

  • PHP code runs on the server, not in the visitor’s browser.
  • PHP can return HTML, JSON, and other response types.
  • Laravel is a framework built with PHP, not a replacement for the language.

Your learning progress

Finish this lesson

Optional practice

PHP playground

This site does not execute learner-provided PHP code. Connect a secured PHP sandbox service before enabling code execution.

Execution is disabled. No code is sent to a server.