Skip to content

Deployment

Getting your Leaf app live should be as simple as building it. Whether you're deploying to shared hosting, VPS, or platforms like DigitalOcean and Vercel, Leaf makes the process smooth and hassle-free. This guide walks you through setting up your server, configuring URL rewriting, and making sure your app runs efficiently in production.

Production Checklist

Before deploying your app, make sure you’ve covered the following:

These are meant to ensure your app runs smoothly in production, without exposing sensitive information or running unnecessary debugging tools.

URL Rewriting

URL rewriting maps all requests to a single entry point—usually index.php—so Leaf’s router can handle them dynamically. Instead of serving files directly, web servers like Apache and Nginx can be configured to route all traffic through your app, so Leaf can handle requests cleanly and efficiently.

nginx
try_files $uri /index.php?$query_string;
apache
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Without this, things like routing, request handling, and error pages won’t work as expected. Make sure to set up URL rewriting correctly on your server to ensure your Leaf app runs smoothly.

Deployment Guides

Okay, now let’s get your app live! 🚀

ProviderDescription
Digital OceanDeploying LeafMVC projects to a new Digital Ocean droplet
HerokuDeploying a base Leaf project to Heroku using the Leaf CLI
Fly.ioDeploying a base Leaf application to Fly.io

Deploying Queues/Workers

When deploying your application with queues, Leaf takes care of setting up the necessary files and commands based on your chosen queue driver. However, once deployed, you’ll need to set up your server to keep your workers running continuously.

For smaller applications, you can keep the queue worker running in the background with:

bash
php leaf queue:work &

This command will set up your queue and start a worker to process jobs. Leaf includes safeguards to prevent excessive memory usage, long-running processes, or crashes from failed jobs. However, for larger applications, this setup may not be enough. In such cases, using a process manager like Supervisor is recommended to ensure your workers run smoothly and restart automatically if needed:

bash
sudo apt update && sudo apt install supervisor -y

Create a new configuration file for your Leaf queue worker:

bash
sudo nano /etc/supervisor/conf.d/leaf-queue.conf

Add your Supervisor configuration:

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

Save and exit, then update Supervisor and start the worker:

bash
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start leaf-queue

This will start a worker that will process jobs in the queue. You can check the status of the worker using the following command:

bash
sudo supervisorctl status leaf-queue

And that's it! Your worker is now running and processing jobs in the queue.

Released under the MIT License.