GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - darklightcode/PHP-Built-in-web-server-Router: PHP Router for PHP Built-in Webserver

BranchesTags
Open more actions menu

Latest commit

 

History

63 Commits
63 Commits

Folders and files

NameName
Last commit message
Last commit date
assets
assets
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
index.js
index.js
 
 
index.php
index.php
 
 
package.json
package.json
 
 

Repository files navigation

Use this only in a development environment

PHP-Built-in-web-server-Router

PHP-Built-in-web-server-Router PHP-Built-in-web-server-Router

This library comes with caching support for PHP built-in web-server

Router.php is loaded before index.php, so you can:

  • Have CORS enabled
  • Set up your environment variables and constants
  • And CACHE EVERYTHING

It also comes with a custom console function to output string|array into terminal ( check out index.php for usage ).

Don't forget to delete it after usage, this function is meant only for Development !

console_output( $string , 'another', array('show'=>1) , ...args )

NODE.JS

I highly recommend node-php-awesome-server if you need a php webserver in a node environment, it uses this router as default router, and much more various configuration options.

npm install node-php-awesome-server --save-dev

If you install this as a npm package you can only retrieve the absolute paths of the router, the library file and a cURL certificate.

npm install php-built-in-web-server-router --save-dev
let router = require('php-built-in-web-server-router');

console.log('Router path: ', router.path);
console.log('Router library: ', router.lib);
console.log('cURL certificate: ', router.cert);

Requirements

PHP 5.4.0+ and /src/mimes.json file.

Usage

Bellow you'll find a few examples. Additional params may be found here

  1. If router.php is located in the root folder
php -S localhost:8000 router.php
  1. If router.php is located in separate folder:
php -S localhost:8000 misc/router.php
  1. If your project structure is something like this, use '-t' parameter to set the document root to your public folder
./www/
    - your_php_framework/
        - private_framework_stuff/
          ...
        - public/
    - misc/
        - router.php
        - mimes.json
    - onefile.php
    
    
 php -S localhost:8000 -t ./your_php_framework/public misc/router.php 

Edit router.php

This are the default settings.

# class PHP_Webserver_Router{...}
#    or   

include('router.class.php');
    
###
# Set up early your environment variables/constants
###
    
$_SERVER["ENVIRONMENT"] = "development";
error_reporting(E_ALL);

 
$php_web_server = new PHP_Webserver_Router();

    
###
# Uncomment to Disable http output in console:
###
//$php_web_server->log_enable = FALSE;

###
# Change this if your "index.php" has another name. By default is index.php
###
//$php_web_server->indexPath = "my_new_index_file.php";

return $php_web_server->listen();

Notes

I've tested this with the following php frameworks:

  • Slim 3 ( the newest addition to this list )
  • Yii2
  • CodeIgniter 3
  • Wordpress 4
  • Drupal 7 and 8

On the first request sent to router.php, it will attempt to download and create mimes.json, if that fails, you can find mimes.json in ./src/ and copy it next to router.php

Personally I bind the webserver to php -S 0.0.0.0 ... so I can test from other remote devices.

Thanks

The method create_mime_file() is a modified version of Josh Sean's generateUpToDateMimeArray function

About

PHP Router for PHP Built-in Webserver

Topics

builtin-serverphpphp-routerphp-serverrouter

Resources

Readme
Activity

Stars

11 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.