{"library":"php-server","title":"Start a PHP Development Server","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install php-server"],"cli":null},"imports":["import phpServer from 'php-server';","import phpServer, { Options as PhpServerOptions } from 'php-server';","import phpServer, { Server as ServerInstance } from 'php-server';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import phpServer from 'php-server';\n\nasync function startServers() {\n  // Basic usage\n  const server1 = await phpServer();\n  console.log(`PHP server running at ${server1.url}`);\n\n  // With custom configuration\n  const server2 = await phpServer({\n    port: 8080,\n    hostname: 'localhost',\n    base: './public',\n    open: true, // Opens browser automatically\n    router: './router.php' // Assuming router.php exists in the project root\n  });\n  console.log(`Custom PHP server running at ${server2.url}`);\n\n  // Example of a simple router.php file (create this in your project root)\n  // router.php:\n  // <?php\n  // if (preg_match('/\\.(?:png|jpg|jpeg|gif|css|js)$/', $_SERVER[\"REQUEST_URI\"])) {\n  //   return false; // Serve the requested resource as-is\n  // } else {\n  //   echo \"<h1>Hello from PHP!</h1>\";\n  //   echo \"<p>URI: \" . $_SERVER[\"REQUEST_URI\"] . \"</p>\";\n  // }\n  // ?>\n\n  // Clean up when done (e.g., on process exit or after tests)\n  // server1.stop();\n  // server2.stop();\n}\n\nstartServers().catch(console.error);","lang":"typescript","description":"Demonstrates how to start a basic PHP server, a customized server with specific port, hostname, base directory, and browser opening, along with type imports.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}