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" | |
} | |
} |