Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Install the Best PHP Micro Frameworks on a Cloud Server

September 28, 2016

4 Min Read
Reading Time: 4 minutes

In software development, we always find ways to perform rapid application development with international code conventions by following standard security and development rules. Although we have several PHP frameworks for development, what about an application which you have to develop in a day or some hours?

The answer lies in PHP micro-frameworks.

best micro php frameworks

What are PHP Microframeworks?

Micro framework is a popular sub classification of web application frameworks that are usually derived from full stack frameworks. They come in handy for small applications that send and receive HTTP requests, route HTTP request to a specific controller, and dispatch and return the controller response. They are commonly used to create API applications for other services or tools.

Popular micro frameworks are based on industry leading frameworks. I will discuss them separately and show you how to install PHP micro frameworks on cloud servers.

Here is the list of best PHP Micro frameworks we are going to cover in this article:

To install these best PHP Rest frameworks on cloud server, I have made a PHP application server on Cloudways by launching a Digital ocean server.

php server stack

Cloudways is also providing a  pre-installed Composer so we don’t need to install it. After launching the application move to your public_html folder and then run the installation commands.

Silex Microframework

Silex is a PHP micro-framework built with Symfony components and Pimple. Silex can be used to make single-page applications. Silex has an extension system based around the Pimple micro service-container that makes it even easier to tie in third party libraries. It uses the symfony HTTPKernel to request and response HTTP requests.

Installation

composer require silex/silex "~2.0"

Code Example 

Simply define a controller and map them to routes

require_once __DIR__.'/../vendor/autoload.php'; 

$app = new Silex\Application(); 

$app->get('/hello/{name}', function($name) use($app) { 
    return 'Hello '.$app->escape($name); 
}); 

$app->run();

You might be interested: Getting Started with Silex Micro-Framework on Cloud Hosting

Slim Framework

Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs. At its core, Slim is a dispatcher that receives an HTTP request, invokes an appropriate callback routine and returns an HTTP response. A slim app contains different routes that respond to specific HTTP requests. To get started, you first initiate and configure the slim app then define controller routes and then run the application.

Installation

composer require slim/slim "^3.0"

Code Example

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

$app = new \Slim\App();
$app->get('/hello/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");

    return $response;
});
$app->run();

You might be interested: Creating a Simple REST API With Slim Framework

Lumen

Lumen is a new project from Laravel creator Taylor Otwell. Lumen depends on the laravel base and working with its components but lumen was built for microservices. Lumen is for projects and components that can benefit from the convenience and power of Laravel, but can afford to sacrifice some configurability and flexibility in exchange for a speed boost.

Installation

//in project folder
composer require "laravel/lumen-installer"

//for global installation
composer global require "laravel/lumen-installer"

After installation you need to set the path of lumen by running the command in SSH.

export PATH="$PATH:$HOME/vendor/bin"

Code Example

<?php

/**
 * Reimagine what you expect...
 */
$app->get('/', function() {
	return ['version' => '5.3']
});

/**
 * From your microframework...
 */
$app->post('framework/{id}', function($framework) {

	$this->dispatch(new Energy($framework));
});

$app->get('api/users/{id}', function($id) {
//some code
});

You might be interested: Creating REST API With Lumen

Bullet PHP

Bullet PHP is a useful microframework used to create REST API that automatically confirms the HTTP request. Bullet is resource and URI-oriented and comes pre-loaded with powerful HTTP features like content-negotiation and caching. Apps in Bullet PHP are built around HTTP URI and defined paths. It handles one code segment at a time and executes the callback for that segment.

Installation

composer require vlucas/bullet PHP

Code Example

$app = new Bullet\App();
$app->path('foo', function($request) use($app) {
    return "foo";
});
$app->path('bar', function($request) use($app) {
    $foo = $app->run('GET', 'foo'); // $foo is now a `Bullet\Response` instance
    return $foo->content() . "bar";
});
echo $app->run('GET', 'bar'); // echos 'foobar' with a 200 OK status

Limonade

Limonade is a PHP microframework for rapid web development and prototyping.It’s inspired by frameworks like Sinatra or Camping in Ruby, or Orbit in Lua. It aims to be simple, lightweight and extremely flexible.

Installation

$ wget https://github.com/sofadesign/limonade/archive/master.zip

Unzip folder in SSH

$ unzip master.zip

Example Code

require_once 'vendors/limonade.php';
dispatch('/', 'hello');
  function hello()
  {
      return 'Hello world!';
  }
run();

Wave Framework

Built loosely on model-view-control architecture and factory method design pattern, Wave is made for web services, websites and info-systems. This microframework is built around native API architecture, caching and smart image and resource management. Wave is a compact framework that does not include optional libraries, has a very small footprint and is developed keeping lightweight speed and optimizations in mind.

Wave comes by default with a view controller and a gateway intended for website functionality with clean URLs that also incorporates a front-end JavaScript controller.

Installation

$wget https://github.com/kristovaher/Wave-Framework/archive/master.zip

Unzip folder in SSH

$ unzip master.zip

Code Example

$apiResult=$this->api('user-login',array('username'=>'bluth','password'=>'123456'));
	if($this->checkTrueFalse($apiResult)){
		// API call was successful
	} else {
		// API call failed, either because of an error or failure response-code
	}

Final Words

Now that you are familiar with the installation of some of the best PHP microframeworks on a Cloud host, there’s no point in dealing with the hassles of shared hosting. There are a few more frameworks, like Flight and Recess PHP, etc., that you can also try on the Cloudways PHP Stack.

If you have any queries about the article or any questions in general, use the comment section below!

Share your opinion in the comment section. COMMENT NOW

Share This Article

Launch PHP websites without the worry of Server Management.

Pre-Installed Optimized Stack with Git, Composer & SSH

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. Besides his work life, he loves movies and travelling. You can email him at shahroze.nawaz@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

BFCM 2019