Create web
directory in same folder as the vendor
directory.
Create index.php
file in web
directory with contents
<?php // web/index.php require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->get("/", function () { return "Hello world!"; }); $app->get("/hello/{name}", function ($name) use ($app) { return "Hello ".$app->escape($name); }); $app->run();
To start app using PHP built-in server run
php -S localhost:8080 -t web
Now you can open the browser and navigate to http://localhost:8080
, to see
Hello World!
We also defined one dynamic route.
Navigate to http://localhost:8080/hello/<YOUR_NAME>
replacing <YOUR_NAME>
with your own name to be greeted by your first Silex app.