Leaf 5 โ App Config & Deployment Reference โ
Environment Variables โ
MVC: auto-loaded. Basic apps: use vlucas/phpdotenv or symfony/dotenv to load .env.
$value = _env('SECRET_KEY', 'default-if-not-found');Application Mode โ
app()->config(['mode' => 'production']);Or set APP_ENV in .env โ Leaf detects it automatically.
Run code only in a specific mode:
app()->script('production', function () {
// only runs in production
});In Blade:
@env('production')
{{-- only renders in production --}}
@endenvProduction 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:
leaf install loggerapp()->config([
'log.enabled' => true,
'log.dir' => __DIR__ . '/logs/',
'log.file' => 'app.log', // default: log.txt
]);To disable logging entirely:
leaf uninstall loggerrescue() โ Safe Execution โ
$value = rescue(function () {
// code that may throw
}, 'default value');
rescue(function () {
// code that may throw โ no return value needed
});Maintenance Mode โ
// Basic app
app()->config(['app.down' => true]);
// MVC โ set in .env
// APP_DOWN=trueCustom down page:
app()->setDown(function () {
echo 'Custom maintenance page!';
});Dependency Injection โ
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:
try_files $uri /index.php?$query_string;Apache (.htaccess):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]Deployment โ
Vite / Inertia Apps โ
Build assets before deploying:
npm run build # or yarn build / pnpm buildSkipping this causes a broken app or CORS errors with Inertia. Add to your deploy script.
Queues / Workers โ
Quick start (small apps):
php leaf queue:work &Production (recommended) โ use Supervisor:
sudo apt update && sudo apt install supervisor -y
sudo nano /etc/supervisor/conf.d/leaf-queue.conf[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.logsudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start leaf-queue
sudo supervisorctl status leaf-queue