Content · Web Development · PHP

Using the PHP Built-In Development Server

php -S runs a lightweight development server, optionally with a router script.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 Admin

php -S runs a lightweight development server, optionally with a router script.

What It Does and When to Use It


Start a development server bound to local loopback. Direct PHP code exposes the underlying operation clearly; a framework can supply lifecycle hooks, dependency wiring and retries.

Requirements, Inputs and Expected Behavior


Confirm the runtime, extension, environment variables, and permissions before running the examples in production. Never expose it to an untrusted network as a production web server.

Example 1: Basic Operation


Start a development server bound to local loopback.

php -S 127.0.0.1:8080 -t public

Example 2: Behavior and Validation


Use a lightweight router script for local experiments.

<?php
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
 if ($path === '/health') {
     header('Content-Type: application/json');
     echo json_encode(['ok' => true]);
     return;
 }
 http_response_code(404); echo 'Not Found';

Practical Example: Application Use


Test the local endpoint, not a public production listener.

php -S 127.0.0.1:8080 -t public router.php
curl --fail http://127.0.0.1:8080/health

Important Behavior and Edge Cases


The second example highlights: Use a lightweight router script for local experiments. The practical example adds: Test the local endpoint, not a public production listener.

Comparison with Related Approaches


ApproachWhat changes
Direct operation versus framework-managed integrationDirect PHP code exposes the underlying operation clearly; a framework can supply lifecycle hooks, dependency wiring and retries.
Choosing safelyChoose based on deployment requirements and verify actual behavior rather than assuming defaults.

Common Beginner Mistakes


MistakeCorrect approach
Assuming successful execution proves the result is usableCheck the return value, required extension, and observable output of the specific operation.
Ignoring runtime and environment differencesVerify PHP version, SAPI, operating system, service access, and permissions before deployment.
Skipping operational constraintsNever expose it to an untrusted network as a production web server.

Key Takeaways


  • php -S runs a lightweight development server, optionally with a router script.
  • Test the local endpoint, not a public production listener.
  • Choose based on deployment requirements and verify actual behavior rather than assuming defaults.
Share this resourceSend this page to someone who may find it useful.