FREE TUTORIAL

Complete Guide Deploy Laravel Application Cpanel Shared Hosting 2025

Deploy Laravel to shared hosting by creating separate archives for root files and public folder contents. Upload root files outside public_html and public files inside it. Create a MySQL database and import your SQL file. Update index.php to point to your Laravel directory and create a production .env file with database credentials. Set storage and bootstrap folders to 755 permissions, other files to 644. Test your deployment to ensure everything works properly.

Difficulty
Intermediate
Duration
30
Learning
Step-by-Step
Share Guide:
Complete Guide Deploy Laravel Application Cpanel Shared Hosting 2025

Table of Contents

Reading Progress
0%

Prerequisites & Requirements

Local Requirements

  • Completed Laravel application
  • Composer installed locally
  • Access to project files
  • Database export (SQL file)

Hosting Requirements

  • cPanel hosting account
  • PHP 8.0+ support
  • MySQL database access
  • File Manager access
Important Note

This tutorial covers shared hosting deployment. For VPS or dedicated servers, the process may differ slightly.

Process Overview

Prepare Files

Organize and compress project files

Upload Files

Upload to correct directories

Setup Database

Create and import database

Configure

Update configuration files

01

Prepare Your Laravel Files

Understanding Directory Structure

Laravel applications have a specific structure. The public folder contains files that should be web-accessible, while everything else should remain private.

Project Structure Map

01your-laravel-app/
02 ├── app/
03 ├── bootstrap/
04 ├── config/
05 ├── database/
06 ├── public/ ← Web accessible files
07 ├── resources/
08 ├── routes/
09 ├── storage/
10 ├── vendor/
11 └── .env

Root Files Archive

Compress everything EXCEPT the public folder into `laravel_root.zip`

app/bootstrap/config/database/resources/routes/storage/vendor/.env.example/artisan/

Public Files Archive

Compress ONLY the contents of the public folder into `laravel_public.zip`

index.php.htaccesscss/js/images/favicon.icorobots.txt

Optimization Routine

Before creating archives, optimize your application for production performance:

Production Optimizationbash
# Optimal dependencies
composer install --optimize-autoloader --no-dev

# Rebuild systematic caches
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Generate ZIP archive
zip -r laravel-app.zip . -x "*.git*" "node_modules/*" "tests/*" ".env"
02

Upload Files to cPanel

2A: Upload Root Files (Private)

1

Open File Manager in cPanel

2

Go to home (outside public_html)

3

Create folder 'laravel_app'

4

Upload & extract root archive

Target Structure

/home/username/
├── public_html/
└── laravel_app/
├── app/
├── bootstrap/
└── ...

2B: Upload Public Files (Web)

1

Navigate to 'public_html'

2

Upload public folder contents

3

Extract directly into root

Critical Deployment Info

Ensure index.php is directly inside public_html. If it's in a subfolder, your site won't load at the domain root.

03

Setup Database

Create MySQL DB

1
Go to "MySQL Databases"
2
Create new database (e.g., _db)
3
Add new user with strong pass
4
Assign user to DB (ALL PRIVILEGES)

Credential Format

DB NAMEusername_laravel_db
USERusername_dbuser
PASS********
HOSTlocalhost
04

Final Configuration

Path Mapping

Your index.php must know where the private Laravel files are hidden.

Update both require paths
Modified index.phpphp
// Point to your private folder
require __DIR__.'/../laravel_app/vendor/autoload.php';

// Load the bootstrapper
$app = require_once __DIR__.'/../laravel_app/bootstrap/app.php';

Production Secrets

Create a fresh .env on the server. Do not repurpose your local one.

APP_DEBUG
False
APP_ENV
Production
System Environmentbash
APP_NAME="Production App"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=prefix_db
DB_USERNAME=prefix_user
DB_PASSWORD=********

Permissions Hardening

Storage Dir

755

Bootstrap Cache

755

Config File (.env)

600

The Danger of 777

Never set folder permissions to 777. This absolute risk exposes your server files to global write operations.

Automation Scripts

Server-Side Deployment Script

deploy.shbash
#!/bin/bash
# High-speed Laravel deployment script

echo "🚀 Syncing logic..."
cd ~/laravel_app
php artisan migrate --force

echo "🧹 Sanitizing caches..."
php artisan config:cache
php artisan route:cache
php artisan view:cache

echo "✅ Deployment operational!"

Testing & Validation

Validation Checklist
Homepage load velocity
Auth session persistence
DB query execution
Asset delivery status
Triage Center
500 ErrorCheck error logs
404 RoutesVerify .htaccess
DB ErrorSync .env prefs
Asset FailReview APP_URL

Project
Operational

Congratulations! You've successfully deployed your Laravel application to shared hosting. Ready for the next architectural challenge?

Featured Insight Sparks

Quick, actionable insights on DevOps, development, and optimization—supercharge your digital projects.