Installation
It's recommended that you use Composer to install Slim.
$ composer require slim/slim "^3.0"
This will install Slim and all required dependencies. Slim requires PHP 5.5.0 or newer.
Usage
Create an index.php file with the following contents:
<?php
require 'vendor/autoload.php';
$app = new Slim\App();
$app->get('/hello/{name}', function ($request, $response, $args) {
return $response->getBody()->write("Hello, " . $args['name']);
});
$app->run();
You may quickly test this using the built-in PHP server:
$ php -S localhost:8000
Going to http://localhost:8000/hello/world will now display "Hello, world".
setup http://localhost:8000/hello/world to http://localhost/hello/world
Create .htaccess file with the following contents:
# Note: see https://httpd.apache.org/docs/current/howto/htaccess.html:
#
# "You should avoid using .htaccess files completely if you have access to
# httpd main server config file. Using .htaccess files slows down your Apache
# http server. Any directive that you can include in a .htaccess file is
# better set in a Directory block, as it will have the same effect with
# better performance."
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]