{"id":13826552,"url":"https://github.com/sindresorhus/php-server","last_synced_at":"2025-10-16T04:54:22.393Z","repository":{"id":55417355,"uuid":"186684015","full_name":"sindresorhus/php-server","owner":"sindresorhus","description":"Start a PHP server","archived":false,"fork":false,"pushed_at":"2024-04-03T09:31:28.000Z","size":14,"stargazers_count":137,"open_issues_count":4,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T07:22:31.363Z","etag":null,"topics":["development","nodejs","npm-package","php","php-server","webserver"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-05-14T19:08:39.000Z","updated_at":"2024-12-30T11:07:56.000Z","dependencies_parsed_at":"2024-04-13T21:44:40.792Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/php-server","commit_stats":{"total_commits":11,"total_committers":2,"mean_commits":5.5,"dds":0.09090909090909094,"last_synced_commit":"e15a2edbf16bc7ccf9450859493a0f9a0e483507"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fphp-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fphp-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fphp-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fphp-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/php-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246515278,"owners_count":20790025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["development","nodejs","npm-package","php","php-server","webserver"],"created_at":"2024-08-04T09:01:40.160Z","updated_at":"2025-10-16T04:54:22.369Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# php-server\n\n\u003e Start a [PHP server](https://php.net/manual/en/features.commandline.webserver.php)\n\nUses PHP's built-in development web server (not for production use).\n\nThe Node.js process is automatically kept alive as long as the PHP server is running.\n\n## Install\n\n```sh\nnpm install php-server\n```\n\n## Usage\n\n```js\nimport phpServer from 'php-server';\n\n// Basic usage\nconst server = await phpServer();\nconsole.log(`PHP server running at ${server.url}`);\n\n// With custom configuration\nconst server2 = await phpServer({\n\tport: 8080,\n\thostname: 'localhost',\n\tbase: './public',\n\topen: true, // Opens browser automatically\n});\n\n// Clean up when done\nserver.stop();\nserver2.stop();\n```\n\n## API\n\n### phpServer(options?)\n\nReturns an object with the following properties:\n\n- `stdout` - The [`subprocess.stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout).\n- `stderr` - The [`subprocess.stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).\n- `url` - The URL to the server.\n- `stop()` - A method, which when called, stops the server.\n\n#### options\n\nType: `object`\n\n##### port\n\nType: `number`\\\nDefault: `0`\n\nThe port on which you want to access the webserver.\n\nSpecify `0` to use a random port.\n\n##### hostname\n\nType: `string`\\\nDefault: `'127.0.0.1'` *(Usually the same as `localhost`)*\n\nThe hostname the server will use.\n\nUse `'0.0.0.0'` if you want it to be accessible from the outside.\n\n##### base\n\nType: `string`\\\nDefault: `'.'`\n\nThe directory the server will serve from.\n\n##### open\n\nType: `boolean | string`\\\nDefault: `false`\n\nOpen the server URL in the browser.\n\nCan be one of the following:\n- `true`: Opens the default server URL (`http://${hostname}:${port}`).\n- A relative path: Opens that path on the server (e.g., `'/about'` opens `http://${hostname}:${port}/about`).\n- An absolute URL: Opens that exact URL (e.g., `'http://localhost:3000'`).\n\n##### env\n\nType: `object`\\\nDefault: `{}`\n\nSet environment variables for the PHP process.\n\n##### router\n\nType: `string`\n\nOptionally specify the path to a [router script](https://php.net/manual/en/features.commandline.webserver.php#example-412) that is run at the start of each HTTP request. If this script returns `false`, the requested resource is returned as-is. Otherwise, the script's output is returned to the browser.\n\nExample router script:\n\n```php\n\u003c?php\n// router.php\nif (preg_match('/\\.(?:png|jpg|jpeg|gif)$/', $_SERVER[\"REQUEST_URI\"])) {\n\treturn false; // Serve the requested resource as-is\n} else {\n\techo \"\u003cp\u003eThanks for using php-server :)\u003c/p\u003e\";\n}\n?\u003e\n```\n\n##### binary\n\nType: `string`\\\nDefault: `'php'` *(The one in your `$PATH`)*\n\nThe path to the PHP binary.\n\nCan be useful if you have multiple versions of PHP installed.\n\n##### ini\n\nType: `string`\\\nDefault: The built-in `php.ini`\n\nA path to a custom [`php.ini` config file](https://php.net/manual/en/ini.php).\n\n##### directives\n\nType: `object`\\\nDefault: `{}`\n\nAdd custom [INI directives](https://php.net/manual/en/ini.list.php).\n\n**Example:**\n\n```js\nconst server = await phpServer({\n\tdirectives: {\n\t\tmemory_limit: '256M',\n\t\tmax_execution_time: '60',\n\t},\n});\n```\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fphp-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fphp-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fphp-server/lists"}