PHP micro-framework

Posted on: May 3, 2020 by Dimitar Ivanov

php-express is a minimal and flexible PHP web application framework that provides a robust set of features for web and mobile applications. php-express is a heavily inspired by Express.js

Figure 1. php-express micro framework
Table of contents


  • PHP >= 7.1
  • JSON extension


If composer is not installed on your system yet, you may go ahead and install it using this command line:

$ curl -sS | php

Next, add the following require entry to the composer.json file in the root of your project.

"require" : {
    "riverside/php-express" : "*"

Finally, use composer to install php-express and its dependencies:

$ php composer.phar install


Make sure that all the requests goes through a single php file.

  • Apache
    <IfModule mod_rewrite.c>
        RewriteEngine On  
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?_path_=$1 [QSA,L]
  • Nginx
    location / {
        try_files $uri $uri/ /index.php$is_args$args;


  • Application - The $app object conventionally denotes the php-express application.
    $app = new \PhpExpress\Application();
  • Request - The $req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on.
    $app->get('/', function ($req, $res) {
        $res->send('HTTP method is: ' . $req->method);
  • Response - The $res object represents the HTTP response that a php-express app sends when it gets an HTTP request.
    $app->get('/readme.txt', function ($req, $res) {
        $res->set('Content-Type', 'text/plain');
        $res->send('foo bar');
  • Router - A $router object is an isolated instance of middleware and routes. You can think of it as a "mini-application", capable only of performing middleware and routing functions. Every php-express application has a built-in app router.
    $router = new \PhpExpress\Router();
    $router->get('/', function ($req, $res) {
        $res->send('foo bar');


php-express support the concepts of Controller and View from the MVC architectural pattern. To employ the Controller concept we need to:

  • specify the class name and method name that will handle the request
  • define the above class and method
$app->get('about.html', '\controllers\basic@about');

This is an example of class basic.

namespace controllers;

class basic {
    public function about($req, $res) {
        $res->send('foo bar');


To employ the View concept in php-express we need to:

  • configure the path to templates using the set() method
  • specify the name of desired template using the render() method
$app->set("views", __DIR__ . "/views");
$app->get('about.html', function ($req, $res) {


The project is hosted on GitHub.


php-express is licensed under the MIT license.

See also
Share this post

If you like the php-express please share this link with your friends and colleagues.


Comments are closed