Slim is a powerful php micro framework which allows developers to create web applications. In this tutorial I am going to describe you about how to install Slim Framework 3.
I will use Composer for installing Slim Framework. So I am assuming that you already install Composer on your Windows machine. If you don’t know how to install composer then check my post how to install composer on windows with XAMPP
First of all create a directory in your xampp/htdocs folder. In my example I am taking testSlim folder. Once testSlim folder is created then create composer.json (file name should be same ) file inside testSlim folder. Now open composer.json and paste following json code.
1 2 3 4 5 6 7 |
{ "require":{ "slim/slim-skeleton": "3.*" } } |
In the above json code “require” key is telling composer about your project dependencies. slim/slim-skeleton is a package name which consist of two parts first part is vendor name and second part is project name. 3.* is a package version which means any version in the 3 development branch or in other words version > 3.0 but < 3.9.
Now open your command prompt using xampp/htdocs/testSlim folder and type composer install.
1 2 3 |
D:\xampp\htdocs\testSlim composer install |
Once you hit composer install, you will see the download process with package information and dependencies just like below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Loading composer repositories with package information Updating dependencies (including require-dev) - Installing psr/log (1.0.0) Downloading: 100% - Installing monolog/monolog (1.18.2) Downloading: 100% - Installing psr/http-message (1.0) Downloading: 100% - Installing slim/php-view (2.1.0) Downloading: 100% - Installing container-interop/container-interop (1.1.0) Downloading: 100% - Installing nikic/fast-route (v0.6.0) Downloading: 100% - Installing pimple/pimple (v3.0.2) Downloading: 100% - Installing slim/slim (3.3.0) Downloading: 100% - Installing slim/slim-skeleton (3.0.1) Downloading: 100% |
Congratulation you have successfully installed Slim Framework on your XAMPP but job is not done right now.
Now goto testSlim folder under htdocs and create index.php file and open it and paste below code in index.php and save it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php require("vendor/autoload.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('/', function (Request $request, Response $response) { echo "hello World"; }); $app->run(); ?> |
Now goto browser and hit testSlim url like http://localhost:8080/testSlim you will see hello World. That’s it.
I have started step by step tutorial on making website using slim 3 framework if you wish to learn click on below link.
Also Read:
- Slim 3 Framework Tutorial: Download, Setup, Create Routes and Template
- Slim 3 Framework Tutorial: Create, Configure, Load and Access Database
Thanks!
Hello Ahsan ! 🙂 Careful, you wrote “composor.json” instead of compos{e}r in your third paragraph ^_^ Thanks !
Thanks for catching that 🙂
Thanks for catching that 🙂
I tried to install Slim through documentation but it did’nt work. Now i did it thanks to you.
Thank you
Your instructions, or at least a link to them, should be put into the slim documentation.
They should title it: Instructions for windows xampp apache users.
Thanks.
I get the following message:
Page Not Found
The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.
Visit the Home Page
When I put the files in the root folder (htdocs) it works, in another folder it gives!