PHP Overview & Environment Setup

What PHP is and where it shines, PHP 8 engine basics, installing PHP with Composer, the request lifecycle, and writing your first HTTP endpoint.

BeginnerUpdated 2026-10-3058K views

What is PHP

PHP is a server-side scripting language built for the web: every request runs a fresh script, echoes HTML (or JSON) and dies. It powers roughly 75% of all websites with a known server language, including WordPress, Laravel ecosystems and countless internal systems.

  • Best for: content sites, admin panels, APIs, rapid prototyping with huge hosting support.
  • Modern PHP (8.x) is fast (JIT), strongly typed by opt-in, and has a mature package ecosystem via Composer.

Installing PHP and Composer

# Windows: 官网 zip 或用 winget
winget install PHP.PHP.8.3
winget install Composer.Composer

# macOS: brew
brew install php composer

# Ubuntu/Debian(ondrej PPA 保持最新版)
sudo add-apt-repository ppa:ondrej/php
sudo apt update && sudo apt install php8.3-cli php8.3-mbstring php8.3-xml
php -v            # PHP 8.3.x (cli)
composer -V
Composer is the de-facto package manager (like npm or pip). require pulls a package from Packagist, generate autoload dumps the class map, and vendor/autoload.php is all you ever include.

Request Lifecycle

HTTP 请求
   │
   ▼
Web 服务器(Nginx/Apache)
   │  FastCGI 协议
   ▼
PHP-FPM 工作进程(常驻,按需 fork)
   │  执行 index.php
   ▼
引导框架 → 路由 → 控制器 → 响应
   │
   ▼
HTTP 响应(进程内状态随请求结束而销毁)

Unlike long-running Node or Go servers, PHP traditionally frees all memory per request — no lingering connections or leaks across requests. PHP-FPM keeps worker processes warm so startup cost is amortized.

Your First Endpoint

<?php
// index.php —— 5 秒启动内置服务器:php -S 127.0.0.1:8080
header('Content-Type: application/json; charset=utf-8');

$name = $_GET['name'] ?? 'BackendWiki';

echo json_encode([
    'message' => "Hello, {$name}",
    'time'    => date('c'),
], JSON_UNESCAPED_UNICODE);

Friends & Partners