Learn SLIM with Real Code Examples
Updated Nov 27, 2025
Installation Setup
Install PHP 8.x or higher and Composer
Create a new project: `composer require slim/slim`
Set up a PSR-7 compatible HTTP server or use built-in PHP server
Optionally install a dependency injection container like PHP-DI
Configure routing and middleware for your application
Environment Setup
Install PHP 8.x+ and Composer
Set up a local server or use built-in PHP server
Install Slim and dependencies via Composer
Configure DI container if needed
Verify by creating a test route
Config Files
composer.json - dependencies
config/settings.php - app configuration
public/index.php - front controller
src/Routes.php - route definitions
src/Middleware.php - middleware registration
Cli Commands
composer require slim/slim - install Slim
php -S localhost:8080 -t public - run dev server
composer require slim/psr7 - PSR-7 HTTP messages
composer require php-di/php-di - optional DI container
vendor/bin/phpunit - run tests
Internationalization
No built-in i18n; use external libraries
Flexible date, time, and number formatting via PHP Intl
UTF-8 encoding by default
Middleware can handle localization
Supports multi-language API responses
Accessibility
Accessible via browser and API clients
Follow web standards for front-end accessibility
Supports multi-language apps through templating engines
Secure session and auth mechanisms implemented manually
Testable via HTTP clients or automated tests
Ui Styling
No built-in UI components
Integrate templating engines like Twig or Plates
Supports JSON/HTML/XML output
Front-end frameworks fully compatible
Custom helpers or middleware for rendering optional
State Management
Request and response objects are immutable
Middleware manages pre/post request processing
Sessions handled manually or via libraries
Cache via external systems like Redis
Dependency injection manages service state
Data Management
No built-in ORM; integrate Eloquent, Doctrine, or other ORM
Data validation via middleware or external libraries
Cache and session handling implemented as needed
Database migrations handled by separate tools
Flexible data management without framework restrictions