Skip to content

Leaf 5 โ€” App Config & Deployment Reference โ€‹

Environment Variables โ€‹

MVC: auto-loaded. Basic apps: use vlucas/phpdotenv or symfony/dotenv to load .env.

php
$value = _env('SECRET_KEY', 'default-if-not-found');

Application Mode โ€‹

php
app()->config(['mode' => 'production']);

Or set APP_ENV in .env โ€” Leaf detects it automatically.

Run code only in a specific mode:

php
app()->script('production', function () {
    // only runs in production
});

In Blade:

blade
@env('production')
  {{-- only renders in production --}}
@endenv

Production Checklist โ€‹

  • Set all environment variables for production
  • Turn off debug mode so errors aren't rendered to your users

Logging โ€‹

MVC: pre-configured. Logs saved to storage/logs/ by default.

Basic apps:

bash
leaf install logger
php
app()->config([
    'log.enabled' => true,
    'log.dir'     => __DIR__ . '/logs/',
    'log.file'    => 'app.log',   // default: log.txt
]);

To disable logging entirely:

bash
leaf uninstall logger

rescue() โ€” Safe Execution โ€‹

php
$value = rescue(function () {
    // code that may throw
}, 'default value');

rescue(function () {
    // code that may throw โ€” no return value needed
});

Maintenance Mode โ€‹

php
// Basic app
app()->config(['app.down' => true]);

// MVC โ€” set in .env
// APP_DOWN=true

Custom down page:

php
app()->setDown(function () {
    echo 'Custom maintenance page!';
});

Dependency Injection โ€‹

php
app()->register('something', function ($c) {
    return new Something();
});

$something = app()->something;
$something->doSomething();

// or
app()->something->doSomething();

URL Rewriting โ€‹

Map all requests to index.php so Leaf's router handles them.

Nginx:

nginx
try_files $uri /index.php?$query_string;

Apache (.htaccess):

apache
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Deployment โ€‹

Vite / Inertia Apps โ€‹

Build assets before deploying:

bash
npm run build   # or yarn build / pnpm build

Skipping this causes a broken app or CORS errors with Inertia. Add to your deploy script.

Queues / Workers โ€‹

Quick start (small apps):

bash
php leaf queue:work &

Production (recommended) โ€” use Supervisor:

bash
sudo apt update && sudo apt install supervisor -y
sudo nano /etc/supervisor/conf.d/leaf-queue.conf
ini
[program:leaf-queue]
process_name=%(program_name)s_%(process_num)02d
command=php leaf queue:work
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/leaf-queue.log
bash
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start leaf-queue
sudo supervisorctl status leaf-queue