Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

jaceju/node-php-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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