PHP Introduction
What PHP is, why it still powers a huge share of the web, installing it, and your first script.
What is PHP?
PHP is a dynamically typed, interpreted scripting language created by Rasmus Lerdorf in 1994, originally as a small set of tools for tracking visits to his personal homepage ("Personal Home Page"). It quickly grew into a full general-purpose language purpose-built for the web, and today is maintained by a wide open-source community and standardized informally through PHP-FIG's PSR standards.
Why PHP still powers a huge share of the web
Despite plenty of "PHP is dying" takes over the years, it remains one of the most widely deployed server-side languages on the internet:
- WordPress alone — powering a huge share of all websites — runs on PHP.
- Major platforms like Facebook (via its HHVM/Hack runtime, a PHP derivative), Wikipedia, Slack's early backend, and countless SaaS products run on PHP.
- Laravel, the framework this very app is built on, is one of the most productive full-stack web frameworks available in any language, and is a major reason modern PHP has a strong reputation among professional teams again.
- It was built specifically for the request/response web model — a PHP script starts, handles one HTTP request, and exits, which makes deployment and reasoning about state simple compared to long-running server processes.
- Modern PHP (8.0+) is fast, strongly typed where you want it to be, and has closed most of the gap that used to exist against languages like Java or C# for large applications.
Installing PHP
Windows — Laragon, XAMPP, or WAMP bundle PHP with a web server and MySQL, which is likely how this very app is running locally. Standalone installers are also available from windows.php.net.
macOS (Homebrew):
brew install php
Linux (Debian/Ubuntu):
sudo apt install php php-cli
Verify the install:
php --version
PHP 8.3.x (cli) (built: ...)
Hello, World — command line
<?php
echo "Hello, World!\n";
php hello.php
Hello, World!
Every PHP file's code lives between <?php and (optionally) ?> tags — a plain .php file with no opening tag is treated as literal HTML/text, not code. echo writes a string directly to standard output.
Hello, World — as a web page
PHP's built-in development server turns any directory into a simple web server with zero configuration — perfect for quick experiments (a real app like this one instead uses a proper web server, but the built-in server is exactly what you reach for while learning):
index.php:
<?php
echo "<h1>Hello, World!</h1>";
php -S localhost:8000
Visiting http://localhost:8000 in a browser now renders the page — PHP executed the script server-side and sent the resulting HTML to the browser. This request/response cycle — script runs, produces output, process ends — is the core mental model behind everything PHP does on the web, from a single index.php file all the way up to a full Laravel application.
Common mistakes
- Forgetting the opening
<?phptag and wondering why the "code" just prints out literally as text. - Using
php -S localhost:8000for anything beyond local development — it's explicitly documented as not meant for production use. - Assuming PHP is still the PHP of the mid-2000s — modern PHP (8.x) has strong typing options, enums,
match, and a completely different performance profile than legacy PHP 5 code.
Interview questions
Q: Why is PHP well suited to the traditional web request/response model? Because a PHP script's lifecycle naturally matches one HTTP request: the script starts fresh, executes, produces output, and exits — there's no long-running process state to manage between requests, which historically made PHP simple to deploy, reason about, and scale horizontally by just adding more web server processes.
Q: What does php -S localhost:8000 do, and when should you NOT use it?
It starts PHP's built-in development web server, serving the current directory over HTTP with zero configuration — extremely convenient for local development and quick testing. It's explicitly not designed for production traffic (it's single-threaded and lacks the performance, security hardening, and process management of a real web server like Nginx or Apache with PHP-FPM), so production deployments always use a proper web server in front of PHP instead.