Laravel best practices
This page collects practical advice for running a fast, stable Laravel application on TurboStack. Laravel is a configuration-only application: the platform provisions PHP, the web server, MySQL and (optionally) Redis, while you bring and deploy your own code through Git deployment. Most performance work therefore happens in your repository, while the platform provides the runtime and services to support it.
Note
Because you control the code, the platform never runs Artisan commands for you. Compiling caches, running migrations and starting workers are steps you build into your own deploy process.
What TurboStack configures for you
When you set an app's type to laravel, the platform applies an opinionated runtime so the framework works without manual web-server editing:
- Nginx vhost with the document root pointing at the application's public directory (
public_html) and the standard front-controller rewrite (try_files $uri $uri/ /index.php?$query_string). This ensures clean URLs and route handling work without additional configuration. - PHP-FPM backend per application, with a generous FastCGI timeout for longer requests and dotfile protection (everything under
/.except/.well-knownis denied). - OPcache available in the PHP runtime to cache compiled bytecode.
- MySQL as the relational database, and Redis when you enable it as a service for cache, sessions and queues.
- Supervisor, available per system user, for keeping long-running processes such as queue workers alive.
Manage these building blocks from the host's Services and Applications tabs.
Recommended optimizations
Combine Laravel's own production guidance with the platform features above.
- Cache configuration and routes - run
php artisan config:cacheandphp artisan route:cachein your deploy so framework bootstrapping is fast. - Cache views and events - add
php artisan view:cache(andevent:cacheif used) to precompile Blade templates and listeners. - Use the optimize shortcut -
php artisan optimizebundles the common production caches in one command. - Enable OPcache - keep OPcache on in your PHP runtime; tune it under Services > PHP advanced options.
- Move cache and sessions to Redis - set
CACHE_STORE=redisandSESSION_DRIVER=redisonce Redis is enabled, to offload the database and the local filesystem. - Run queues on Redis - use
QUEUE_CONNECTION=redisand process jobs with a worker rather than thesyncdriver for slow tasks (mail, exports, webhooks). - Keep workers alive - run
php artisan queue:workunder a supervisor so jobs process continuously and restart on failure. Use the per-user Supervisor, or run the worker as a user system service. To clear a backlog faster, run several workers in parallel - but keep the total within the host's processor budget (see Scale throughput with more instances). - Schedule with the scheduler - point a single cron entry at
php artisan schedule:runevery minute and define tasks in Laravel rather than many crontab lines. - Optimize the autoloader - deploy with
composer install --no-dev --optimize-autoloaderto drop dev dependencies and speed up class loading. - Optimize assets - build front-end assets ahead of deploy (e.g.
npm run buildwith Vite) and serve them as static files; add a Content Delivery Network (CDN) for heavy media.
Tip
After any code or config change, re-run the cache commands. Stale config:cache output is a common cause of "my .env change had no effect".
Sizing and scaling
TurboStack auto-tunes service memory from the host's resources, so the defaults suit most Laravel sites. Override the tuning variables only when you have measured evidence (slow queries, Redis evictions, OPcache restarts):
Make one change at a time and re-measure. See Performance tuning for the full method, and scale PHP-FPM workers there too.
Stability
- Back up before changes - confirm Backups cover the database and any user-uploaded files in
storage/. - Watch Health - monitor CPU, memory and service status, especially after a deploy.
- Keep versions current - track Laravel long-term support (LTS) and PHP releases, and bump the PHP runtime under Services on a supported version.
- Test on a staging clone - validate upgrades, migrations and cache changes on a copy before publishing to production.
- Run migrations deliberately - include
php artisan migrate --forcein your deploy step and review it for destructive changes first.
Related
- Deploy Laravel on TurboStack
- Troubleshooting Laravel
- How to manage user system services
- Services
- Performance tuning