Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active July 4, 2025 13:15
Show Gist options
  • Save masakielastic/4882f48c95ed6f92c7b33897f1b8d2a1 to your computer and use it in GitHub Desktop.
Save masakielastic/4882f48c95ed6f92c7b33897f1b8d2a1 to your computer and use it in GitHub Desktop.
php-node で phpinfo のページを表示させる

php-node で phpinfo のページを表示させる

npm init -y
npm install @platformatic/php-node
package.json
index.js
public/info.php
import { Php, Request } from '@platformatic/php-node';
import http from 'http';
const php = new Php({ docroot: new URL('./public', import.meta.url).pathname });
http.createServer(async (req, res) => {
const request = new Request({
method: req.method,
url: `http://localhost${req.url}`,
headers: Object.fromEntries(Object.entries(req.headers).map(([k, v]) => [k, Array.isArray(v) ? v : [v]])),
});
const response = await php.handleRequest(request);
response.headers.forEach((vals, name) => res.setHeader(name, vals));
res.write(response.body);
res.end();
}).listen(3000, () => {
console.log('Server running at http://localhost:3000/info.php');
});
<?php
phpinfo();
{
"name": "php-node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"@platformatic/php-node": "^1.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment