PHP includes a small built-in web server that can serve a project during development. It is useful for quick checks and simple demos, but it is not a replacement for a production web server.
Start the server
From the project directory, run:
php -S 127.0.0.1:8000 -t public
The -t option sets the document root. Binding to 127.0.0.1 keeps the server local to the machine. Open http://127.0.0.1:8000/` in a browser. If the application uses a front controller, a router script may be supplied as the final argument.
Use a router script when needed
A router script can let existing static files pass through while sending application routes to index.php. Keep routing behavior simple and avoid using the development server to test Apache-specific directives such as .htaccess or Nginx configuration.
Know the limits
The built-in server is intended for development and is not designed for public production use. Its behavior, concurrency and request handling differ from PHP-FPM behind Apache or Nginx. It does not validate production TLS, reverse-proxy headers, process management or deployment permissions.
Use it as one test layer
It is excellent for checking a controller, template or JSON endpoint quickly. Before release, test the application behind the actual web-server stack, with the production PHP runtime, URL rewriting, session settings and file permissions.
Further reading
- PHP built-in web server: https://www.php.net/manual/en/features.commandline.webserver.php