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.
npm install php-serverVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to start a basic PHP server, a customized server with specific port, hostname, base directory, and browser opening, along with type imports.
Upgrade your Node.js environment to version 20 or later. Use a Node.js version manager like `nvm` or `volta` if you need to manage multiple versions.
Ensure your Node.js environment is version 18 or later. For current versions, refer to the latest breaking changes.
Refactor your imports from `const phpServer = require('php-server');` to `import phpServer from 'php-server';`. Ensure your project is configured for ESM, potentially by adding `"type": "module"` to your `package.json` or by using `.mjs` file extensions.Ensure you are on `php-server` v3.0.0 or later to correctly utilize the `open` option with absolute URLs or relative paths. Review its usage if migrating from an older version.
Ensure PHP is installed and accessible via your system's PATH. Alternatively, use the `binary` option to provide the explicit path to your PHP executable, e.g., `phpServer({ binary: '/usr/local/bin/php' })`.Change `const phpServer = require('php-server');` to `import phpServer from 'php-server';`. If your project is CommonJS, you'll need to configure it to support ESM imports, typically by adding `"type": "module"` to your `package.json` or changing the file extension to `.mjs`.Verify that PHP is installed on your system and its executable is added to your system's PATH environment variable. If PHP is installed in a non-standard location, provide the full path to the `php` binary using the `binary` option, e.g., `phpServer({ binary: '/path/to/php/bin/php' })`.Ensure you `await` the `phpServer()` call to get the actual server object before attempting to call `.stop()`. Example: `const server = await phpServer(); server.stop();`.
No dependency data recorded yet.