Deploying Laravel 11 Cleanly on Shared cPanel & LiteSpeed Hosting Without Downtime or Zombie Processes
Not every client needs an AWS cluster. Here is how to structure public_html, avoid LiteSpeed CSRF cache poisoning, and keep RAM usage under 50MB on shared cPanel hosting.
Many agencies push small businesses onto expensive cloud clusters when a well-configured LiteSpeed cPanel server can comfortably serve thousands of daily visitors for a fraction of the cost. The trick is knowing the exact pitfalls of shared cPanel hosting with Laravel 11.
1. Keep Application Code Outside public_html
Never upload your entire Laravel repository directly into public_html/. If a misconfigured .htaccess ever exposes directory listing, your .env file is instantly public. Instead:
- Place the core application (
app/,config/,database/,resources/,routes/,storage/,vendor/,.env) in a sibling directory such as/home/username/app_core/. - Place only the contents of Laravel's
public/folder inside/home/username/public_html/. - Update the two paths in
public_html/index.phpto point to../app_core/vendor/autoload.phpand../app_core/bootstrap/app.php.
2. Beware of LiteSpeed Full-Page HTML Caching on Stateful Laravel Routes
This is the single most common bug we see on LiteSpeed Laravel deployments. If you enable E=Cache-Control:max-age=900 for guest GET requests in .htaccess, LiteSpeed caches the full rendered HTML in RAM for 15 minutes.
That causes two immediate problems:
- Stale deployments: Running
php artisan view:clearonly clears Laravel's disk cache—LiteSpeed keeps serving the old HTML from RAM until 15 minutes pass. - CSRF token poisoning (
419 Page Expired): Laravel embeds Visitor A's session-bound@csrftoken inside forms and<meta name="csrf-token">. When LiteSpeed serves that cached HTML to Visitor B, Visitor B's form submission fails with HTTP 419.
Unless you fetch CSRF tokens asynchronously via JS on form focus, keep X-LiteSpeed-Cache-Control: no-cache on dynamic HTML routes and cache static assets (.css, .js, .webp, .woff2) for 1 year instead.
3. Watch Your Background Processes and Memory
Shared cPanel accounts enforce strict CloudLinux LVE limits on Physical Memory and Number of Processes. Never run a permanent php artisan queue:work daemon via cron—every minute cron will spawn another copy until your account hits 100% RAM. Always use --stop-when-empty --max-time=50 or lightweight scheduled commands, and audit active processes periodically with ps -u username to catch orphaned workers from old deployments.
Need help architecting a Laravel backend, Kotlin Android app, or joining our weekend engineering cohort?