Install Slim Framework and Write Your First "Hello World"

By Budyks    PHP

You want to create a simple Website but you don't want to start from scratch or a complex Framework ? You need to try Slim Framework

Installing Slim Framework would be much easier if we're using Composer.

Create a folder (your project folder) in your Web server (htdocs for apache users). for example we create "slim" . create a new file "composer.json" inside slim and type this : 

{    "require": {        "slim/slim": "2.*"    }}

Open you terminal and make sure its under slim folder for example

root@AcerXtimeline:/opt/lampp/htdocs/slim#

now type : composer install or php composer.phar install (depending on how you install the composer). If you follow this Composer Install Tutorial, you just need the first option

 root@AcerXtimeline:/opt/lampp/htdocs/slim# composer install

You'll see the process

Loading composer repositories with package informationInstalling dependencies (including require-dev)  - Installing slim/slim (2.4.3)    Downloading: 100%         Writing lock fileGenerating autoload files

Once its done, create index.php and type : 

require "vendor/autoload.php";
$app = new \Slim\Slim();
$app->get("/",function(){
    echo "Hello World";});
$app->run();

Also edit .htaccess file :

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [QSA,L] 

so you can now open it in Browser : 

http://localhost/slim

Comments



    Follow Us