How to Deploy a Laravel Project on Shared Hosting (Step-by-Step Guide)

Author

Kritim Yantra

Jun 17, 2025

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

  1. Go to cPanel → MySQL Databases.
  2. Create a database + user, and assign permissions.

3.2 Update .env

Since you can’t edit .env directly on shared hosting:

  1. Rename .env.example to .env (if allowed).
  2. 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 -Indexes to .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:

  1. Open storage/logs/laravel.log.
  2. 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

  1. Set up cron jobs (for queues/schedules) via cPanel.
  2. Enable caching (config:cache, route:cache).
  3. 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!

Ajay Yadav

Ajay Yadav

Senior Full-Stack Engineer

7 + Years Experience

Transforming Ideas Into Digital Solutions

I architect and build high-performance web applications with modern tech:

Laravel PHP 8+ Vue.js React.js Flask Python MySQL

Response time: under 24 hours • 100% confidential

Tags

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Sign in with Google

Related Posts