Install Slim Framework di Debian 7
Slim adalah Framework PHP yang mudah, cepat dan handal untuk membangun web aplikasi.
Slim 3 membutuhkan php 5.5 dan mod_rewrite tentuntya butuh apache / Nginx web server, disini memakai apache dan php 5.5 dengan mod_rewrite
1. Install php 5.5
tambahkan repo dotDEB (kambing.ui.ac.id)
edit file /etc/apat/source.list
# mirror DOTDEB NGINX
deb http://kambing.ui.ac.id/dotdeb/ wheezy all
deb-src http://kambing.ui.ac.id/dotdeb/ wheezy all
# Hapus komentar
# mirror DOTDEB PHP 5.4
#deb http://kambing.ui.ac.id/dotdeb/ wheezy-php54 all
#deb-src http://kambing.ui.ac.id/dotdeb/ wheezy-php54 all
# Hapus komentar
# mirror DOTDEB PHP 5.5
deb http://kambing.ui.ac.id/dotdeb/ wheezy-php55 all
deb-src http://kambing.ui.ac.id/dotdeb/ wheezy-php55 all
# Hapus komentar
# mirror DOTDEB PHP 5.6
#deb http://kambing.ui.ac.id/dotdeb/ wheezy-php56 all
#deb-src http://kambing.ui.ac.id/dotdeb/ wheezy-php56 all
2. Fetch dan install the GnuPG key
root@php:/#wget http://www.dotdeb.org/dotdeb.gpg
root@php:/#apt-key add dotdeb.gpg
root@php:/#apt-get update
root@php:/#apt-get install php5
3. install composer
root@php:/#apt-get install curl php5-cli php5-curl
user@php:/>cd /usr/src
user@php:/usr/scr>curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
user@php:/> composer --version
user@php:/>Composer version 1.0-dev (1c525b76f81123af180743d31c208c29351cf931) 2015-12-09 15:47:26
4. install slim
user@php:/>cd /var/www
user@php:/var/www/>composer require slim/slim "^3.0"
bikin file script index.php untuk testing slim
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
// $app = new \Slim\App;
$app = new \Slim\App ();
$app->get ( "/", function (Request $request, Response $response) {
echo "Hello World";
} );
$app->get ( '/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute ( 'name' );
$response->getBody ()->write ( "Hello, $name" );
return $response;
} );
$app->run ();
// $app->run();
5. Testing buka via browser https://[ip-server]
6. Testing dengan paramater https://[ip-server]/index.php/hello/nama ku tux
Slim 3 membutuhkan php 5.5 dan mod_rewrite tentuntya butuh apache / Nginx web server, disini memakai apache dan php 5.5 dengan mod_rewrite
1. Install php 5.5
tambahkan repo dotDEB (kambing.ui.ac.id)
edit file /etc/apat/source.list
# mirror DOTDEB NGINX
deb http://kambing.ui.ac.id/dotdeb/ wheezy all
deb-src http://kambing.ui.ac.id/dotdeb/ wheezy all
# Hapus komentar
# mirror DOTDEB PHP 5.4
#deb http://kambing.ui.ac.id/dotdeb/ wheezy-php54 all
#deb-src http://kambing.ui.ac.id/dotdeb/ wheezy-php54 all
# Hapus komentar
# mirror DOTDEB PHP 5.5
deb http://kambing.ui.ac.id/dotdeb/ wheezy-php55 all
deb-src http://kambing.ui.ac.id/dotdeb/ wheezy-php55 all
# Hapus komentar
# mirror DOTDEB PHP 5.6
#deb http://kambing.ui.ac.id/dotdeb/ wheezy-php56 all
#deb-src http://kambing.ui.ac.id/dotdeb/ wheezy-php56 all
2. Fetch dan install the GnuPG key
root@php:/#wget http://www.dotdeb.org/dotdeb.gpg
root@php:/#apt-key add dotdeb.gpg
root@php:/#apt-get update
root@php:/#apt-get install php5
3. install composer
root@php:/#apt-get install curl php5-cli php5-curl
user@php:/>cd /usr/src
user@php:/usr/scr>curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
user@php:/> composer --version
user@php:/>Composer version 1.0-dev (1c525b76f81123af180743d31c208c29351cf931) 2015-12-09 15:47:26
4. install slim
user@php:/>cd /var/www
user@php:/var/www/>composer require slim/slim "^3.0"
bikin file script index.php untuk testing slim
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
// $app = new \Slim\App;
$app = new \Slim\App ();
$app->get ( "/", function (Request $request, Response $response) {
echo "Hello World";
} );
$app->get ( '/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute ( 'name' );
$response->getBody ()->write ( "Hello, $name" );
return $response;
} );
$app->run ();
// $app->run();
5. Testing buka via browser https://[ip-server]
Komentar
Posting Komentar