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.
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
composer require slim/psr7
Nyholm PSR-7 and Nyholm PSR-7 Server
composer require nyholm/psr7 nyholm/psr7-server
Guzzle PSR-7 and Guzzle HTTP Factory
composer require guzzlehttp/psr7 http-interop/http-factory-guzzle
Zend Diactoros
composer require zendframework/zend-diactoros
Step 4: Hello World
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
$app->get('/', function (Request $request, Response $response, $args) {
$response->getBody()->write("Hello world!");
return $response;
});
$app->run();