Module 2: PHP Environment and InstallationBeginner40 min read
PHP CLI, Built-in Server, PHP-FPM, FastCGI & php.ini Configuration
Set up PHP on Windows/Linux/macOS, compare PHP CLI vs PHP-FPM/FastCGI web execution, and configure php.ini for development vs production.
Key Takeaways & Core Concepts
- Stacks: XAMPP (cross-platform), WAMP (Windows), LAMP (Linux), MAMP (macOS), or Docker.
- Built-in Dev Server: Run
php -S localhost:8000 -t public/for local development (never use in production!). - CLI SAPI: Executes scripts in terminal (
php script.php), no HTTP headers, unlimited execution time by default. - PHP-FPM (FastCGI Process Manager): Pool of long-lived worker processes behind Nginx/Apache. Handles high concurrency without spawning a new OS process per request.
1. Development Stacks & Built-in Server
- Stacks: XAMPP (cross-platform), WAMP (Windows), LAMP (Linux), MAMP (macOS), or Docker.
- Built-in Dev Server: Run
php -S localhost:8000 -t public/for local development (never use in production!).
1. Inspecting Runtime SAPI & Configuration
1<?php
2echo "SAPI: " . PHP_SAPI . "\n";
3echo "Major Version: " . PHP_MAJOR_VERSION . "\n";
4echo "Memory Limit: " . ini_get('memory_limit') . "\n";
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
4 lines
Note: `PHP_SAPI` reports whether PHP is running via `cli` or `fpm-fcgi`; `ini_get` reads `php.ini` settings.
2. PHP CLI vs. Web SAPI (PHP-FPM & FastCGI)
- CLI SAPI: Executes scripts in terminal (
php script.php), no HTTP headers, unlimited execution time by default. - PHP-FPM (FastCGI Process Manager): Pool of long-lived worker processes behind Nginx/Apache. Handles high concurrency without spawning a new OS process per request.
3. `php.ini`: Development vs. Production
| Directive | Development | Production |
|---|---|---|
display_errors | On | Off (log instead!) |
error_reporting | E_ALL | E_ALL & ~E_DEPRECATED |
opcache.enable | 1 | 1 (huge speedup) |
Practice & AssessmentPHP Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)