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.

Table of Contents
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
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
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
Root Files Archive
Compress everything EXCEPT the public folder into `laravel_root.zip`
Public Files Archive
Compress ONLY the contents of the public folder into `laravel_public.zip`
Optimization Routine
Before creating archives, optimize your application for production performance:
# 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"Upload Files to cPanel
2A: Upload Root Files (Private)
Open File Manager in cPanel
Go to home (outside public_html)
Create folder 'laravel_app'
Upload & extract root archive
Target Structure
2B: Upload Public Files (Web)
Navigate to 'public_html'
Upload public folder contents
Extract directly into root
Ensure index.php is directly inside public_html. If it's in a subfolder, your site won't load at the domain root.
Setup Database
Create MySQL DB
Credential Format
username_laravel_dbusername_dbuser********localhostFinal Configuration
Path Mapping
Your index.php must know where the private Laravel files are hidden.
// 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_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
Bootstrap Cache
Config File (.env)
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
#!/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
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.