Thursday 23 August 2018

Install Slim Framework and Write Your First "Hello World"


Do you want to create a simple website but do you 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 or php install 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 information
Installing dependencies (including require-dev)
  - Installing slim / slim (2.4.3)
    Downloading: 100%
Writing lock file
Generating 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 On
RewriteCond% {REQUEST_FILENAME}! -F
RewriteRule ^ index.php [QSA, L]


so you can now open it in Browser:

http: // localhost / slim

Share this


0 Comments