vtardia/simphle

This package is abandoned and no longer maintained. No replacement package was suggested.

A quick and simple PHP server for development

1.0.3 2016-02-11 17:29 UTC

This package is auto-updated.

Last update: 2022-01-23 21:10:11 UTC


README

Simphle is a friendly wrapper for PHP built-in web server, with some handy features for an easy developement.

Requirements

Installation

  1. Composer
$ composer [global] require vtardia/simphle

Use the global option to install it globally on your system

  1. Custom

Clone this repository to a shared directory, for example /usr/local/php/simphle or /Users/Shared/php/Simphle on a Mac, then run composer install.

Add the bin directory to your local path or create a link to the bin/simphle executable:

   $ ln -s /usr/local/php/simphle/bin/simphle ~/bin/simphle

Usage

Basic

Start a server with default settings in the current directory:

$ cd /path/to/myapp/docroot
$ simphle

Intermediate

Start a server with custom settings from the command line:

$ cd /path/to/myapp
$ simphle [-H host] [-p port] [-c path/to/php.ini] [-r path/to/router.php] [path/to/docroot]

Advanced

Create a server.json file in your project's directory with your custom settings and then launch simphle from inside that path.

{
    "host":"0.0.0.0",
    "port":5000,
    "docroot":"public",
    "router":"myrouter.php|default",
    "ini":"mysettings.ini|default",
    "controller": "mycontroller.php",
    "env": {
        "myvar": "somevalue",
        "anothervar": {
            "one": "foo",
            "two": "bar"
        }
    }
}

The router and ini file paths are relative to the current working directory. The main Simphle script searches for these files in the current working directory first, then in Simphle's share directory. The .php and .ini extensions are not required for preset router and INI files.

The controller file path is relative to the document root directory.

Launch it with Composer

Create a scripts section in you composer.json:

"scripts": {
    "server": "simphle [options]"
}

Then launch it using

$ composer server

The default router

Simphle's default router tries to simulate a typical Apache .htaccess file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

If the requested URI exists tries to fetch it, if not it searches for an index.php, finally falls back to a "404 not found" error.

Using a front controller

By specifying a controller settings Simphle uses this file as rewrite target instead of index.php, so you can use for example app.php.

Customizing the environment

The env section defines environment variables that are passed to the PHP files through the $_ENV superglobal. JSON objects are converted to associative arrays.

Sometimes the $_ENV superglobal is not populated. It depends on the variables_order settings in php.ini:

; This directive determines which super global arrays are registered when PHP
; starts up. If the register_globals directive is enabled, it also determines
; what order variables are populated into the global space. G,P,C,E & S are
; abbreviations for the following respective super globals: GET, POST, COOKIE,
; ENV and SERVER. There is a performance penalty paid for the registration of
; these arrays and because ENV is not as commonly used as the others, ENV is
; is not recommended on productions servers. You can still get access to
; the environment variables through getenv() should you need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order = "GPCS"

This setting can be overridden by local htaccess or php.ini files.

License

Simphle is licensed under the MIT License - see the LICENSE file for details