Skip to main content
RU Digital Services
Laravel & Backend 3 min read •

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.

AA
Aaqib Khalique
Chief Technology Officer (CTO) • RU Digital Services

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.php to point to ../app_core/vendor/autoload.php and ../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:

  1. Stale deployments: Running php artisan view:clear only clears Laravel's disk cache—LiteSpeed keeps serving the old HTML from RAM until 15 minutes pass.
  2. CSRF token poisoning (419 Page Expired): Laravel embeds Visitor A's session-bound @csrf token 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.

Written by Aaqib Khalique

Need help architecting a Laravel backend, Kotlin Android app, or joining our weekend engineering cohort?

Related Engineering Guides

All articles →
Send Inquiry WhatsApp Chat
Cookie & Privacy Notice

We use essential cookies to maintain security and authentication, as well as optional analytical cookies to deliver relevant content and analyze traffic. Read our Privacy Policy.