How to Deploy a Laravel Project on Shared Hosting (Step-by-Step Guide)
Deploying a Laravel application on shared hosting can be tricky, but it’s absolutely possible! Many budget-friendly hosting providers (like Bluehost, HostGator, or SiteGround) don’t offer full server control, but with the right steps, you can get your Laravel app running smoothly.
This guide covers:
✅ Pre-deployment checklist
✅ Uploading files correctly
✅ Configuring the database
✅ Fixing common shared hosting issues
Let’s dive in!
🔍 Before You Start: Shared Hosting Limitations
Most shared hosting environments have:
✔ No SSH access (or limited)
✔ No Composer pre-installed
✔ Restricted folder permissions
✔ No direct .env file editing
But don’t worry! We’ll work around these limitations.
🚀 Step 1: Prepare Your Laravel Project for Shared Hosting
1.1 Remove Unnecessary Files
Delete:
node_modules/vendor/(we’ll reinstall it).git/(if you don’t need version control on the server)
1.2 Compile Assets for Production
Run:
npm run prod
This generates minified CSS/JS in /public.
1.3 Install Dependencies Locally
Run:
composer install --optimize-autoloader --no-dev
This ensures only production-ready packages are installed.
📤 Step 2: Upload Files to Shared Hosting
2.1 Use FTP/SFTP (FileZilla, Cyberduck, or cPanel File Manager)
Upload:
- All Laravel files except
/public - Inside
/public_html, upload only the contents of/public
2.2 Correct Folder Structure
Your hosting’s public_html should look like this:
/public_html/
├── index.php
├── assets/
├── .htaccess
└── (other public files)
The rest of Laravel (app, routes, vendor) should be outside public_html (e.g., in /laravel).
2.3 Modify index.php (Critical Step!)
Since Laravel expects files in /public, but shared hosting forces public_html, update:
// Before
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
// After (adjust path if needed)
require __DIR__.'/../../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
🔧 Step 3: Configure the Database
3.1 Create a MySQL Database
- Go to cPanel → MySQL Databases.
- Create a database + user, and assign permissions.
3.2 Update .env
Since you can’t edit .env directly on shared hosting:
- Rename
.env.exampleto.env(if allowed). - Use cPanel’s "File Manager" to edit
.env:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=your_db_name
DB_USERNAME=your_db_user
DB_PASSWORD=your_db_password
⚙️ Step 4: Fix Permissions & Security
4.1 Set Correct Permissions
Run these via cPanel’s "File Manager" (or FTP):
storage/→ 755 (or 775 if possible)bootstrap/cache/→ 755
4.2 Secure Your App
- Disable directory listing (add
Options -Indexesto.htaccess). - Force HTTPS (if SSL is installed):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
🚦 Step 5: Test & Troubleshoot
Common Issues & Fixes
| Issue | Solution |
|---|---|
| 500 Server Error | Check .env, permissions, and storage/logs. |
| CSS/JS Not Loading | Ensure paths in mix-manifest.json are correct. |
| Database Connection Failed | Verify credentials in .env. |
Check Laravel Logs
If you see a blank page:
- Open
storage/logs/laravel.log. - Look for errors.
🎯 Final Checklist Before Going Live
✔ All Laravel files uploaded (except public/).
✔ /public contents moved to public_html.
✔ .env configured with correct DB details.
✔ Permissions set (storage/ and bootstrap/cache/).
✔ HTTPS enforced (if using SSL).
🚀 Next Steps
- Set up cron jobs (for queues/schedules) via cPanel.
- Enable caching (config:cache, route:cache).
- Monitor performance (check CPU usage in cPanel).
💡 Pro Tip: Use a Deployment Script
If your host allows SSH access, automate deployments with:
git pull origin main
composer install --optimize-autoloader --no-dev
php artisan migrate --force
php artisan optimize
📌 Conclusion
Deploying Laravel on shared hosting isn’t ideal, but it’s totally doable with the right steps. By carefully organizing files, configuring .env, and setting permissions, you can run Laravel even on budget hosting.
Need help? Drop a comment below! 👇
🚀 Happy deploying!
Projects related to this guide
Use the concepts from this article in practical source-code projects.
Flask Authentication System (Free Version) - Kritim Yantra
🛠 Features✔ Google & GitHub Authentication✔ User Registration & Login✔ Profile/Dashboard Access✔ Secure...
Python Flask Blog Project with Admin Panel
Are you ready to launch a powerful, modern, and fully customizable blog? Look no further! Introducing the Flask-...
Laravel 12 + ReactJS Starter Kit: Add Multi-Language Support (Arabic, English, Spanish) with Blog CRUD
🚀 Installation & Setup Download & Extract Get the ZIP from kritimyantra.com and extract it. Includes pr...
Comments
No comments yet. Be the first to comment.
Sign in to join the discussion.