jaceju / node-php-server

Create a built-in PHP server in your node.js script
MIT License
29 stars 4 forks source link

node-php-server Build Status

Deprecated!! Please use gulp-connect-php.

Create a built-in PHP server for PHP framework in node.js script.

Install

npm install --save node-php-server

Examples

var phpServer = require('node-php-server');

// Create a PHP Server
phpServer.createServer({
    port: 8000,
    hostname: '127.0.0.1',
    base: '.',
    keepalive: false,
    open: false,
    bin: 'php',
    router: __dirname + '/server.php'
});

// Close server
phpServer.close();

server.php

<?php
// Example from Laravel framework
return call_user_func(function () {
    $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    $publicDir = __DIR__ . '/public';
    $uri = urldecode($uri);

    $requested = $publicDir . '/' . $uri;

    if ($uri !== '/' && file_exists($requested)) {
        return false;
    }

    require_once $publicDir . '/index.php';
});

License

MIT