Web developers building dynamic sites or testing PHP projects locally can run their code on a Windows PC. PHP executes server-side scripts, can be embedded in HTML, and also runs scripts from the command line.
How does local PHP testing work?
PHP includes a built-in development server for previewing a project in a browser. From a terminal, start it in the project folder with a command such as php -S 127.0.0.1:8000, then open that local address. The server executes PHP files as requests arrive, so page output can reflect submitted form data or other request details.
HTML, forms, and sessions
A PHP file can mix server-side code with HTML. When a request reaches the server, PHP runs the code and sends the resulting page to the browser. Form values are available through request data such as $_GET and $_POST; session data can be maintained across requests with PHP's session features.
- Use PHP code to generate page content based on a request.
- Process submitted form values on the server.
- Keep per-user session data between page requests.
Command-line scripts and extensions
The PHP command-line interpreter runs scripts directly, which suits maintenance tasks, data processing, and other jobs that do not start with a browser request. PHP extensions add functionality, including database connections. The php.ini configuration file controls runtime settings and which extensions are enabled, so the command-line and web-server setups may need their own configuration.
Pros
- Embeds PHP logic in HTML pages
- Built-in server serves local projects for browser testing
- Command-line execution supports scripts outside web requests
- Extensions add database and other service integrations
System requirements: 32-bit and 64-bit · Visual C++ Redistributable for Visual Studio 2015–2022 (x64 or x86)
Can PHP serve a local site without Apache?
Yes. PHP's built-in development server can serve a project locally for browser testing.
Can PHP run scripts without a web browser?
Yes. The command-line interpreter runs PHP scripts directly.
How does PHP handle form submissions?
Server-side scripts can read submitted values through request data such as $_GET and $_POST.