Installation

System Requirements

  • Web server with URL rewriting
  • PHP 7.1 or newer

Step 1: Install Composer

Don’t have Composer? It’s easy to install by following the instructions on their download page.

Step 2: Install Slim

We recommend you install Slim with Composer.Navigate into your project’s root directory and execute the bash commandshown below. This command downloads the Slim Framework and its third-partydependencies into your project’s vendor/ directory.

  1. composer require slim/slim:4.0.0

Step 3: Install a PSR-7 Implementation and ServerRequest Creator

Before you can get up and running with Slim you will need to choose a PSR-7 implementation that best fits your application.In order for auto-detection to work and enable you to use AppFactory::create() and App::run() without having to manually create a ServerRequest you need to install one of the following implementations:

Slim PSR-7

  1. composer require slim/psr7

Nyholm PSR-7 and Nyholm PSR-7 Server

  1. composer require nyholm/psr7 nyholm/psr7-server

Guzzle PSR-7 and Guzzle HTTP Factory

  1. composer require guzzlehttp/psr7 http-interop/http-factory-guzzle

Zend Diactoros

  1. composer require zendframework/zend-diactoros

Step 4: Hello World

  1. <?php
  2. use Psr\Http\Message\ResponseInterface as Response;
  3. use Psr\Http\Message\ServerRequestInterface as Request;
  4. use Slim\Factory\AppFactory;
  5. require __DIR__ . '/../vendor/autoload.php';
  6. $app = AppFactory::create();
  7. $app->get('/', function (Request $request, Response $response, $args) {
  8. $response->getBody()->write("Hello world!");
  9. return $response;
  10. });
  11. $app->run();