PHP is an open-source, general-purpose scripting language designed especially for web development. In a web application, PHP normally runs on the server and creates the response that a browser receives.
After this lesson, you will be able to trace a PHP page from browser request to server execution, identify which code stays on the server, and run a small script through a web server or the command line.
PHP stands for PHP: Hypertext Preprocessor. It can be embedded inside HTML, but it is also a complete language with variables, functions, classes, exceptions, file handling, database extensions, and command-line tools.
PHP is commonly used to read an HTTP request, apply application rules, communicate with a database or service, and produce HTML, JSON, a file, or another response.
When a browser requests a PHP page, the web server passes the file to the PHP runtime. PHP executes the server-side instructions and produces a response that the server returns to the browser.
The browser receives generated output, not the original PHP source. Private application logic therefore stays on the server, while secrets still belong in protected environment configuration rather than source files.
PHP source files normally use the .php extension. The opening tag <?php starts PHP code, while <?= is a short form of <?php echo for inserting a value into HTML.
In a file that contains only PHP, omit the closing ?> tag to prevent accidental trailing whitespace from becoming response output.
The server evaluates the variable before returning the completed paragraph.
<?php
$completedLessons = 2;
?><h1>PHP Learning Dashboard</h1>
<p>Lessons completed: <?= $completedLessons ?></p>
<h1>PHP Learning Dashboard</h1>
<p>Lessons completed: 2</p>
The browser receives the value 2 in ordinary HTML. It never sees the $completedLessons assignment.
PHP and browser JavaScript usually cooperate. PHP prepares data and the initial response on the server; JavaScript updates the interface after the response reaches the browser.
| Question | PHP | Browser JavaScript |
|---|---|---|
| Where does it run? | On the server before the response is sent | In the browser after code is downloaded |
| Typical work | Application rules, authentication, database access, response creation | Events, interface updates, browser APIs |
| Can visitors inspect it? | Not in a correctly configured response | Yes, downloaded code is inspectable |
For a web page, you need PHP, a web server, and a browser. XAMPP supplies Apache and PHP together: save a .php file under the configured web root, start Apache, and request the file through localhost.
For a command-line script, run php filename.php. On a default Windows XAMPP installation, use C:\xampp\php\php.exe filename.php when php is not available on PATH.
<?php
echo 'PHP is running.' . PHP_EOL;
PHP is running.
PHP_EOL adds the correct line ending for the operating system.
0 of 2 checked
Apply the request flow
0 of 2 completed
Explore 500+ free tutorials across 20+ languages and frameworks.