Registry / devops / php-server

php-server

JSON →
library3.0.0jsnpmunverified

php-server is a utility that simplifies the process of starting PHP's built-in development web server directly from Node.js applications. It's designed for development environments, not production, and provides an API to control the server, including specifying port, hostname, base directory, and custom PHP configurations like INI directives or a router script. The package is currently at version 3.0.0 and maintains an active release cadence, primarily driven by Node.js version updates. Key differentiators include its simple API for programmatic control, automatic process management, and seamless integration with Node.js development workflows, making it easy to spin up a quick PHP backend for testing or local development without managing separate PHP processes manually. It is a pure ESM package.

devopsweb-framework
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The package is pure ESM since v1.0.0. CommonJS `require` is not supported.

import phpServer from 'php-server';

Use `Options` for type hinting in TypeScript. The primary export is the default function.

import phpServer, { Options as PhpServerOptions } from 'php-server';

The `Server` interface represents the return type of `phpServer()` for type hinting in TypeScript, providing `url`, `stdout`, `stderr`, and `stop()` method.

import phpServer, { Server as ServerInstance } from 'php-server';

Demonstrates how to start a basic PHP server, a customized server with specific port, hostname, base directory, and browser opening, along with type imports.

import phpServer from 'php-server'; async function startServers() { // Basic usage const server1 = await phpServer(); console.log(`PHP server running at ${server1.url}`); // With custom configuration const server2 = await phpServer({ port: 8080, hostname: 'localhost', base: './public', open: true, // Opens browser automatically router: './router.php' // Assuming router.php exists in the project root }); console.log(`Custom PHP server running at ${server2.url}`); // Example of a simple router.php file (create this in your project root) // router.php: // <?php // if (preg_match('/\.(?:png|jpg|jpeg|gif|css|js)$/', $_SERVER["REQUEST_URI"])) { // return false; // Serve the requested resource as-is // } else { // echo "<h1>Hello from PHP!</h1>"; // echo "<p>URI: " . $_SERVER["REQUEST_URI"] . "</p>"; // } // ?> // Clean up when done (e.g., on process exit or after tests) // server1.stop(); // server2.stop(); } startServers().catch(console.error);
Debug
Known footguns
breakingVersion 3.0.0 of `php-server` requires Node.js version 20 or higher. Previous versions of Node.js are no longer supported.
breakingVersion 2.0.0 of `php-server` required Node.js version 18 or higher. Projects running on older Node.js versions needed to upgrade.
breakingVersion 1.0.0 transitioned `php-server` to be a pure ES Module (ESM). This means it can no longer be imported using `require()` in CommonJS environments.
gotchaThe `open` option in `phpServer` can now accept an absolute URL, a relative path, or a boolean. Prior to v3.0.0, handling of absolute URLs might have been incorrect, leading to unexpected browser behavior.
gotchaIf the `php` binary is not found in the system's PATH, `php-server` will fail to start. This is a common issue in environments where PHP is not globally installed or its path is not configured.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
Resources