Your First Application
This guide walks you through building a simple “Hello World” web application with Marko, introducing key concepts along the way.
1. Create the Project
Section titled “1. Create the Project”composer create-project marko/skeleton hello-markocd hello-marko2. Register Your Module
Section titled “2. Register Your Module”Create an app/foo directory for your local module. It needs a composer.json to be recognized as a module:
{ "name": "app/foo", "type": "marko-module", "autoload": { "psr-4": { "App\\Foo\\": "src/" } }, "extra": { "marko": { "module": true } }}3. Create a Controller
Section titled “3. Create a Controller”Controllers handle HTTP requests. Create one using PHP attributes to define routes:
<?php
declare(strict_types=1);
namespace App\Foo\Controller;
use Marko\Routing\Attributes\Get;use Marko\Routing\Http\Response;
class GreetingController{ #[Get('/hello/{name}')] public function greet(string $name): Response { return new Response( body: "Hello, {$name}! Welcome to Marko.", ); }}4. Start and Test
Section titled “4. Start and Test”marko upmarko openIf
markoisn’t installed yet, runcomposer global require marko/clifirst. See Installation for details.
This opens the site up in your browser. Then, just navigate to http://localhost:8000/hello/World and you’ll see:
Hello, World! Welcome to Marko.5. Add a JSON Endpoint
Section titled “5. Add a JSON Endpoint”Marko makes JSON responses simple:
<?php
declare(strict_types=1);
namespace App\Foo\Controller;
use Marko\Routing\Attributes\Get;use Marko\Routing\Http\Response;
class ApiController{ #[Get('/api/hello/{name}')] public function greet(string $name): Response { return new Response( body: json_encode(['message' => "Hello, {$name}!", 'framework' => 'Marko']), headers: ['Content-Type' => 'application/json'], ); }}What You’ve Learned
Section titled “What You’ve Learned”- Modules are Composer packages with
marko.module: true - Routes are defined with PHP attributes (
#[Get],#[Post], etc.) - Controllers are plain classes — no base class inheritance required
- Marko auto-discovers modules in
app/,modules/, andvendor/
Next Steps
Section titled “Next Steps”- Learn about project structure in detail
- Understand dependency injection to wire services together
- Add a database to persist data