GitXplorerGitXplorer
h

node-phpcgi

public
32 stars
11 forks
3 issues

Commits

List of commits on branch master.
Unverified
da86e40b691ba689088134d7407ebc97ed6c0dd9

update

hhushicai committed 8 years ago
Unverified
34b12c91a1718920e157e14090da80b6a671b79b

bump to 0.3.7

hhushicai committed 8 years ago
Unverified
4fefb8bc7308d3c96425e3ebe4b6fb4f98f63b2a

use webpack

hhushicai committed 8 years ago
Unverified
5017d7dc0a5ea89f0884057797a3cbc6894892fb

update

hhushicai committed 8 years ago
Unverified
4bb511e8887f37ac855bef8bd88bda47eecd09b0

update readme

hhushicai committed 8 years ago
Unverified
ee58a3bc70fccb0f24cda64ee9abebb79926457d

add koa support

hhushicai committed 8 years ago

README

The README file for this repository.

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-phpcgi

Then, 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/php/bin/php-cgi'
});
var app = connect();
app.use(phpcgi);

If you are using koa2, you can use it like this:

const Koa = require('koa');
const app = new Koa();

const phpcgi = require('node-phpcgi/koa');

app.use(phpcgi({documentRoot: __dirname}));

Specially for edp, you can use it like this:

{
    location: /\.php($|\?)/,
    handler: [
        require('node-phpcgi/edp')()
    ]
}

Customize

If you want to specify the arguments for php, just add them:

var middleware = phpcgi({
    documentRoot: __dirname,
    // change it to your own path
    handler: '/usr/local/php/bin/php-cgi'
    // you can add any available php-cgi args here.
    args: ['-c', '/usr/local/php/lib/php.ini']
});

Test

Clone into somewhere:

git clone https://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/php/bin/php-cgi'
});

If you does not install the global mocha, install it:

npm install -g mocha

After that, you can do this:

# cd the repo directory
npm install
mocha

This package is inspired from gateway.