Skip to main content
Support Hours: 24/7 (technical team 11 AM to 8 PM PKT)WhatsApp: +92 313 2946143
Hosting Infrastructure
16 min read
Updated Oct 7, 2026 • Published Sep 28, 2026

How to Deploy a Laravel Application on cPanel & VPS in 2026: The Secure Zero-Downtime Guide

Step-by-step production deployment guide for Laravel 11/12 on cPanel shared hosting and Ubuntu VPS. Avoid common security vulnerabilities, set up storage symlinks, configure Composer dependencies, and automate queue workers.

Muhammad Anees Ur Rehman
Founder & Infrastructure Architect
Share Guide:
How to Deploy a Laravel Application on cPanel & VPS in 2026: The Secure Zero-Downtime Guide

The Reality of Deploying Modern Laravel Applications on Web Hosting

In short: To deploy Laravel on cPanel, upload the project outside public_html, point the domain to Laravel's public folder, set up .env and the database, run Composer and migrations, and add the scheduler as a cron job. A VPS follows the same steps with Nginx.

Laravel is the world's most popular PHP framework. It powers modern web applications, SaaS platforms, and APIs across Pakistan's tech industry.

However, moving a Laravel app from local development to production hosting often creates hurdles for developers.

Unlike legacy PHP scripts, Laravel strictly separates application logic from public assets. The web entry point resides exclusively in /public, while private configuration, database credentials, and storage remain in the parent directory.

Deploying incorrectly can expose your .env file or cause broken asset routing.

This complete 2026 guide shows how to deploy Laravel securely on both cPanel shared hosting and Ubuntu VPS servers.

Laravel 11 deployment pipeline on cPanel showing public root isolation and artisan caching.
Figure 1: Production deployment pipeline isolating the web document root and optimizing config cache.
  • Security First: The .env file containing your database passwords, APP_KEY, and mail credentials must never be accessible via HTTP.
  • Document Root Alignment: Only the contents of Laravel's public/ directory should be exposed to public web traffic.
  • Composer in Production: Always install dependencies with --no-dev --optimize-autoloader to ensure maximum performance and minimum disk footprint.
  • Production Caching: Run artisan config:cache, route:cache, and view:cache to eliminate runtime parsing overhead.
Key Takeaway: Never dump your entire Laravel repository directly into public_html. Always isolate private application logic outside the public web root to prevent catastrophic credential leaks.

The #1 Security Mistake: Exposing the.env File on cPanel

In our technical audits of hundreds of Pakistani web applications, by far the most dangerous security flaw discovered is developers dragging and dropping their entire Laravel root directory directly into public_html and using .htaccess hacks to redirect traffic to /public.

Why is this a catastrophic mistake? If Apache's rewrite module encounters a syntax error or .htaccess parsing is bypassed, any automated vulnerability scanner can request https://yourdomain.com/.env directly. When this happens, the web server serves the .env file as plain text, handing hackers your:

  • MySQL database hostname, username, and password.
  • Mail server credentials (SMTP username and password).
  • Third-party API secret keys (Stripe, JazzCash, AWS S3, Twilio).
  • APP_KEY (allowing attackers to forge session cookies and execute remote code).

To prevent this, the authoritative production standard for cPanel shared hosting is to place the entire Laravel project folder one level above public_html in your user home directory.

Key Takeaway: Security vulnerability #1 in Laravel deployments is exposing the root directory inside public_html. Storing files one level above the web root completely isolates your application from direct HTTP access.

The Architecturally Correct Directory Topology for cPanel Shared Hosting

Here is the exact directory architecture you should establish in cPanel File Manager or via SSH terminal:

text
/home/username/
├── laravel_app/ <-- [PRIVATE: Out of web reach]
│ ├── app/
│ ├── bootstrap/
│ ├── config/
│ ├── database/
│ ├── routes/
│ ├── storage/
│ ├── vendor/
│ ├──.env <-- 100% PROTECTED
│ ├── artisan
│ └── composer.json
└── public_html/ <-- [PUBLIC: Accessible via Web]
 ├── index.php <-- Points back to../laravel_app/
 ├──.htaccess
 ├── robots.txt
 ├── favicon.ico
 ├── build/ <-- Compiled Vite / React / Vue assets
 └── storage/ <-- Symbolic link to../laravel_app/storage/app/public

By keeping laravel_app outside public_html, it is physically impossible for any web visitor to download your .env file, browse internal controller code, or view error logs.

Comparison of Laravel task scheduling in cPanel cron vs VPS Supervisor daemons.
Figure 2: Architectural differences between cron-driven task scheduling and persistent queue workers.

Configuring public_html/index.php

Copy the contents of your Laravel project's public/ folder directly into public_html. Then, open public_html/index.php and edit lines referencing the autoloader and bootstrap file to point one directory up (../laravel_app):

php
// Change this:
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

// To this:
require __DIR__.'/../laravel_app/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel_app/bootstrap/app.php';

Step-by-Step cPanel Deployment Workflow via Terminal / SSH

On Alif Host, all developer hosting plans provide SSH terminal access. Here is the exact CLI sequence to deploy your Laravel application cleanly:

1. Clone Your Repository into user root

Log into your account via SSH and clone your private repository:

bash
cd ~
git clone https://github.com/yourbrand/your-laravel-repo.git laravel_app
cd laravel_app

2. Configure Production Environment & Dependencies

Copy the environment file, input your cPanel MySQL database credentials, and install production dependencies without dev tools:

bash
cp.env.example.env
nano.env
# Set APP_ENV=production, APP_DEBUG=false, and input DB credentials

composer install --no-dev --optimize-autoloader
php artisan key:generate
php artisan migrate --force

3. Set Up Public Directory & Storage Symlink

Copy public assets and generate the symbolic storage link:

bash
# Copy public assets into public_html
cp -r ~/laravel_app/public/* ~/public_html/
cp ~/laravel_app/public/.htaccess ~/public_html/

# Fix paths in public_html/index.php as shown above
# Generate the storage symlink
ln -s ~/laravel_app/storage/app/public ~/public_html/storage

4. Execute Production Caching Directives

Compile and cache configuration, routes, and views for instantaneous execution:

bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache

Automating Laravel Tasks: Setting Up cPanel Cron for the Scheduler

Laravel includes an integrated task scheduler that allows you to schedule background jobs (such as automated emails, invoice generation, subscription renewals, and database pruning) using a single cron job entry.

Instead of configuring separate cron entries for every command in cPanel, you only need to register the master Laravel scheduler cron entry:

  1. In cPanel, navigate to the Cron Jobs tool under the Advanced section.
  2. Under Common Settings, select *Once Per Minute (` `)**.
  3. In the Command field, input the exact path to your PHP binary and the Laravel artisan script:
bash
/usr/local/bin/php /home/username/laravel_app/artisan schedule:run >> /dev/null 2>&1

Every minute, the cPanel cron daemon evaluates your application's routes/console.php or app/Console/Kernel.php scheduler definitions and executes due tasks automatically without any manual server maintenance.

Key Takeaway: A single cron entry running php artisan schedule:run every minute powers all background maintenance, notifications, and recurring tasks seamlessly.

Advanced Production Setup: Deploying Laravel on an Ubuntu VPS with Nginx

For high-traffic applications, enterprise SaaS platforms, and APIs handling millions of daily requests, deploying on a dedicated Cloud VPS running Ubuntu, Nginx, PHP-FPM, and Supervisor queue workers offers maximum speed and isolation.

High-Performance Nginx Server Block Configuration

Create a virtual host configuration in /etc/nginx/sites-available/yourdomain.com:

nginx
server {
 listen 80;
 listen [::]:80;
 server_name yourdomain.com www.yourdomain.com;
 root /var/www/laravel_app/public;

 add_header X-Frame-Options "SAMEORIGIN";
 add_header X-Content-Type-Options "nosniff";

 index index.php index.html;
 charset utf-8;

 location / {
 try_files $uri $uri/ /index.php?$query_string;
 }

 location = /favicon.ico { access_log off; log_not_found off; }
 location = /robots.txt { access_log off; log_not_found off; }

 error_page 404 /index.php;

 location ~ \.php$ {
 fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
 fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
 include fastcgi_params;
 fastcgi_hide_header X-Powered-By;
 }

 location ~ /\.(?!well-known).* {
 deny all;
 }
}

Supervisor Configuration for Continuous Queue Workers

To process asynchronous background jobs (such as dispatching order emails and generating PDF invoices without slowing down user web requests), configure Supervisor in /etc/supervisor/conf.d/laravel-worker.conf:

ini
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel_app/artisan queue:work database --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=4
redirect_stderr=true
stdout_logfile=/var/www/laravel_app/storage/logs/worker.log
stopwaitsecs=3600

Production Hardening Checklist: OPcache, Redis, and Permissions

Before opening your Laravel application to public users, verify these essential security and performance settings:

  • File Permissions: Directories must be 755 and files 644. The storage and bootstrap/cache folders must be writable by the web server user (chown -R www-data:www-data storage bootstrap/cache).
  • Enable PHP OPcache: Ensure OPcache is active in your PHP configuration to cache precompiled bytecode in RAM, reducing CPU load by over 50%.
  • Session & Cache Drivers: For high-traffic applications, switch your session and cache drivers from file to redis in .env for sub-millisecond in-memory throughput.
  • Force HTTPS & HSTS: Enforce HTTPS redirection using free Let's Encrypt SSL certificates to ensure all user data and credentials are encrypted in transit.
Frequently Asked Questions

Common Questions Answered

Can I run Laravel migrations on cPanel shared hosting without SSH?

While SSH terminal access is the fastest method, if you do not have SSH enabled, you can temporarily create a secure web route in routes/web.php protected by an administrative secret token that invokes Artisan::call('migrate', ['--force' => true]). Alternatively, you can import your migrated database schema directly via phpMyAdmin in cPanel.

Why does Laravel show a 404 error when clicking links on cPanel?

This almost always indicates that your .htaccess file was missed during public file copying. Ensure the official Laravel .htaccess file resides in public_html so Apache correctly rewrites all virtual URI requests to index.php?$query_string.

How do I update a deployed Laravel application with zero downtime?

Deploy using Git version control. First enable maintenance mode via php artisan down --secret='your-bypass-token', pull the latest code with git pull origin main, run composer install --no-dev --optimize-autoloader, execute database migrations with php artisan migrate --force, refresh caches with php artisan optimize, and disable maintenance mode via php artisan up.

What PHP version is required for Laravel 11 and 12?

Laravel 11 and 12 require PHP 8.2 or PHP 8.3 as the absolute minimum requirement, along with core extensions including OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype, JSON, and BCMath. All Alif Host shared and VPS servers provide native support for PHP 8.2 and PHP 8.3 with these extensions enabled by default.

Muhammad Anees Ur Rehman
Written & Audited By

Muhammad Anees Ur Rehman

Founder & Infrastructure Architect • 3+ Years Experience

Muhammad Anees Ur Rehman is the Founder and Chief Infrastructure Architect at Alif Host. With 3+ years of hands-on work in Linux web hosting, LiteSpeed server optimization, and cloud virtualization, Anees builds and runs the hosting infrastructure behind Alif Host for Pakistani businesses, e-commerce stores, and digital agencies. A staunch advocate for transparent hosting policies and local payment integration (JazzCash, Easypaisa, Raast), he regularly publishes deep-dive technical benchmarks on server response times, WordPress performance, and cyber resiliency.

LiteSpeed Web Server TuningKVM Cloud VirtualizationcPanel & WebHost Manager (WHM)
View Full Author Profile & Articles
Featured Hosting & Infrastructure

Related Hosting & Infrastructure Solutions

Dedicated KVM ResourcesStarting at PKR 2,600/month

VPS Hosting in Pakistan with Dedicated NVMe Storage

Reliable virtual private servers with dedicated compute resources, pure NVMe storage, 1Gbps unmetered uplink, and local payment gateways in Pakistan.

VPS Hosting in Pakistan with Dedicated NVMe Storage
Remote DesktopStarting at PKR 3,200/month

Windows RDP Server in Pakistan: Plans and Price in PKR

Dedicated Windows Remote Desktop access with guaranteed RAM and NVMe storage for forex trading, accounting software, and continuous remote workstations.

Windows RDP Server in Pakistan: Plans and Price in PKR

Related Educational Articles

Back to Blog