# Installation

Leaf 3 release 🎊

The official leaf 3 release candidate has been released.

Leaf 3 is built by design to be incrementally adoptable. This means that it can be integrated into a project multiple ways depending on the requirements.

There are four primary ways of adding Leaf PHP to a project:

  1. Use the Leaf CLI (opens new window) to scaffold a project [RECOMMENDED].
  2. Download leaf through composer
  3. Use Leaf skeleton (opens new window) to quickstart your project
  4. Download the leaf repo


If you want to migrate an existing Leaf 2 project, skip this and follow the Migration Guide

# Release Notes

Latest version 3 release: Latest Stable Version

Detailed release notes this version available on GitHub (opens new window).

# Leaf CLI

Video Docs

You can take a look at our leaf cli setup walkthrough on youtube.

Watch the leaf 3 installation walkthrough

Leaf provides an official CLI (opens new window) for quickly creating and managing your Leaf applications. It takes just a few seconds to get up and running with your leaf app. See the Leaf CLI docs for more details.

leaf create <project-name> --v3

You can also install modules using the following syntax:

leaf install cors

You can then run your app using:

leaf serve

# Composer

You can also set up a new leaf 3 project from scratch using composer:

# latest stable (v3)
$ composer require leafs/leaf

# version 3 dev
$ composer require leafs/leaf dev-v3.x-dev

After insalling Leaf, you need to create your index.php file which will be the entry point to your application.


require __DIR__ . "/vendor/autoload.php";

app()->get("/", function () {
  response()->json(["message" => "Hello World!"]);


You might want to check out URL rewriting.

# GitHub

You can also clone the leaf 3 branch.

Setup ☁️

You can directly download v3.x-dev here.

After downlaoding repo, you need to create an autoloader.

Example autoloader: autoloader.php

spl_autoload_register(function ($class) {
  $file = str_replace('\\', '/', $class);

  if (!file_exists("leaf/src/$file.php")) return;

  require "leaf/src/$file.php";

The autoloader will allow you use leaf files without having to require or include them first. So straight up using Leaf\App will load leaf\src\App.php.

This is only required if you downloaded the repo.

Now, all you have to do is create your index.php file, install leaf's dependencies (core modules), and include your autoloader like this:


require __DIR__ . "leaf/vendor/autoload.php";
require __DIR__ . "autoloader.php";


functional mode is not automatically available if you go down this route, you will have to manually add the leaf functions file in your app or in the autoloader.



require __DIR__ . "leaf/vendor/autoload.php";
require __DIR__ . "autoloader.php";
require __DIR__ . "leaf/src/functions.php";

Although the setup for this method is a bit more complicated, it gives you full control over leaf and how it works since you will have access to the source code. You can directly edit leaf to behave the way you want it to. If you don't need this, we recommend that you install leaf with composer above or if you want a base setup, you can follow either of the methods below.

# Leaf skeleton

Leaf skeleton is an official leaf boilerplate that packs a default setup with optional MVC configuration and setup.


Skeleton with Leaf 3 is also available on the leaf cli. You can quickly scaffold a skeleton 3 project with:

leaf create <project-name> --skeleton --v3

The main installtion for skeleton is through composer.

composer create-project leafs/skeleton <project-name>