Cloudways

@cloudways

How to Install Top PHP Micro Frameworks on a Cloud Server

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 microframeworks.

What are Micro Frameworks?

Micro framework is a term used for web application frameworks, usually derived from full stack frameworks. They are helpful in making applications which send and receive HTTP requests, routing HTTP request to the specific controller, and dispatch and return the controller response. They are commonly used to make API applications for other services or tools.

There are lots of Micro frameworks derived from different frameworks. We will discuss them separately and how you can easily install them on cloud servers.

Top PHP Micro frameworks

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

  • Silex
  • Slim
  • Lumen
  • Bullet PHP
  • Limonade
  • Wave Framework

To install Restful microframeworks on cloud server, I have made a PHP application server on Cloudways by launching a Digital ocean server.

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 microframework 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();

Slim Framework

Slim is a PHP microframework 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();

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
});

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 top 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!

Originally published at www.cloudways.com on September 28, 2016.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMIfamily. We are now accepting submissions and happy to discuss advertising &sponsorship opportunities.
To learn more, read our about page, like/message us on Facebook, or simply, tweet/DM @HackerNoon.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

More by Cloudways

Topics of interest

More Related Stories