Package Exports
- node-phpcgi
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-phpcgi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-phpcgi
A simple middleware for node to execute php with php-cgi.
Foreword
Before using this, make sure you have already installed the php-cgi
Note:Not the php command.
Quick Start
First, install it in your project directory:
npm install node-phpcgiThen, use it in your node server like this:
var middleware = require('node-phpcgi')({
documentRoot: __dirname,
// change it to your own handler path
handler: '/usr/local/php/bin/php-cgi'
});
var app = http.createServer(function(req, res) {
middleware(req, res, function(err) {});
});If you are using connect, you can use it like this:
var connect = require('connect');
var phpcgi = require('node-phpcgi')({
documentRoot __dirname,
// change it to your own path
handler: '/usr/local/php2/bin/php-cgi'
});
var app = connect()
.use(phpcgi);Specially, for edp, in the edp-webserver-config.js:
// ...
var phpcgi = require('node-phpcgi')({
documentRoot: __dirname,
// change it to your own handler path
// note: double backslash char `\\` in windows style path
// windows: "C:\\Program Files\\PHP\\php-cgi.exe"
handler: '/usr/local/php/bin/php-cgi'
});
// ...
exports.getLocations = {
return [
// ...
{
location: /\.php($|\?)/,
handler: [
function(context) {
context.stop();
phpcgi(context.req, context.res, function(err, data) {
context.start();
});
}
]
}
// ...
];
};Test
Clone into somewhere:
git clone git@github.com:hushicai/node-phpcgi.git Before you can run the tests, you should change the handler path in the test/spec.js file:
var middleware = phpcgi({
documentRoot: __dirname + '/htdocs',
// change it to your own path
handler: '/usr/local/php2/bin/php-cgi'
});After that, you can do this:
npm install -g mocha
# cd the repo directory
npm install supertest
mochaThis package is inspired from gateway.