Deploying to Shared Hosting
Leaf runs on the cheapest kind of hosting there is: a shared plan with cPanel (or something like it), a file manager or FTP, and no terminal. You build the app on your own computer, upload the files, and it runs. No server to manage, no database server to pay for if you use SQLite.
This guide covers Leaf MVC apps. It assumes your host gives you PHP 8.2 or newer, Apache with .htaccess support (almost every cPanel host does), and the pdo_sqlite extension if you use SQLite.
1. Prepare the upload on your computer
Your host has no Composer, so install dependencies before you upload:
composer install --no-dev --optimize-autoloaderThen set your .env for production:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://your-domain.com/If you use SQLite (the default for new projects), create the database now so you upload it ready to go:
leaf db:migrateThe database lands in storage/app/db/database.sqlite. Leave out anything you don't need on the server, such as node_modules/ and tests/.
2. Upload, choosing one of two layouts
Option A: upload the whole project into public_html
This is the quickest way, and it is safe in projects created from Leaf MVC 5 onwards. Upload your whole project folder's contents into public_html (or www, htdocs, whatever your host calls it). The .htaccess file at the root of your project sends every request into public/, so your .env, database, vendor/ and app code can't be downloaded.
Older projects
If your project doesn't have an .htaccess file at its root, add this one before uploading. Without it, anyone can download your .env and your database.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/\.well-known/
RewriteRule (^|/)\. - [F,L]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
Require all denied
</IfModule>After uploading, open https://your-domain.com/.env in your browser. You should get a 403 or 404. If you can see the file, your host isn't reading .htaccess; use option B instead.
Option B: keep the app above public_html
This is the textbook layout, and it doesn't depend on .htaccess for protection:
/home/you/
├── my-app/ ← everything except public/
└── public_html/ ← the contents of public/- Upload the project, minus
public/, into a folder next topublic_html(here,my-app). - Upload the contents of
public/intopublic_html. - In
public_html/index.php, point Leaf at the app folder:
$appPath = dirname(__DIR__) . '/my-app';3. Running Leaf commands without a terminal
Most hosts don't give you SSH, but almost all of them have cron jobs, and a cron job can run any Leaf command. To run migrations once on the server, add a cron job in cPanel, let it run once, then delete it:
cd /home/you/my-app && php leaf db:migrateUse the full path to your app folder. If the job doesn't run, your host may name PHP differently (for example /usr/local/bin/php or ea-php83); cPanel's cron page usually shows the right one.
Checklist
APP_ENV=productionandAPP_DEBUG=falsein the uploaded.env/.envreturns 404 in the browserstorage/is writable by PHP (cPanel's file manager can set this to755)- Your host's PHP version is 8.2 or newer, set in cPanel under "Select PHP Version" or "MultiPHP Manager"
