DEV Community

Brian
Brian

Posted on

How to Deploy a Laravel App on Shared Hosting (The Right Way)

Not every project needs a VPS or cloud infrastructure. If you're working with a tight budget or launching a side project, shared hosting might be your go-to.

But deploying a Laravel app on shared hosting isn’t as straightforward as uploading files — it requires a few tweaks. In this guide, I’ll walk you through how to deploy Laravel properly on a cPanel-style shared hosting environment.


🧰 What You’ll Need

  • A Laravel project (locally tested)
  • Access to shared hosting (cPanel-based)
  • PHP 8.1+ on the server
  • Database (MySQL)
  • FTP or File Manager access

📁 Step 1: Prepare Laravel for Production

Before uploading anything, clean and prep your Laravel project:

  1. Update environment config in .env.production:
   APP_ENV=production
   APP_DEBUG=false
   APP_URL=http://yourdomain.com
Enter fullscreen mode Exit fullscreen mode


`

  1. Run the following commands locally:


php artisan config:cache
php artisan route:cache
php artisan view:cache

  1. Zip everything except node_modules and .git.

📦 Step 2: Upload Files to the Server

  1. Log in to your hosting panel.
  2. Open File Manager and go to the root of your site (usually public_html).
  3. Upload your zipped Laravel project.
  4. Extract it there — it will create a folder like laravel-app.

🔁 Step 3: Point public/ to the Root

Laravel’s entry point is public/index.php, but shared hosting expects everything in public_html. Two options:

✅ Option 1: Move Files (Recommended)

Move everything from laravel-app/public/ into public_html/.

Then edit index.php in public_html:

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

➡ Change paths to:

php
require __DIR__.'/../laravel-app/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';

⚠️ Option 2: Use .htaccess Rewrite

(Not ideal. Option 1 is more stable and secure.)


🛠️ Step 4: Set Permissions

Ensure proper permissions:


chmod -R 755 storage
chmod -R 755 bootstrap/cache

Some hosts allow this via the file manager. Others might need support help.


🛢️ Step 5: Configure the Database

  1. In cPanel, create a new MySQL database and user.

  2. Grant the user full access to the DB.

  3. In your .env file (on the server), update the following:

env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_db
DB_USERNAME=your_user
DB_PASSWORD=your_password

  1. Then run migrations by visiting:


http://yourdomain.com/artisan/migrate

Or trigger it using a route/controller if CLI is unavailable.


🧪 Step 6: Test Everything

  • Visit http://yourdomain.com
  • Make sure routes, DB, and views load
  • Check for permission issues in logs (storage/logs)

💡 Bonus Tips

  • Use php artisan storage:link manually by creating a symlink via cPanel Terminal
  • Use a custom .htaccess to force HTTPS and pretty URLs
  • Don’t upload .env locally — create it on the server from .env.production

✅ Conclusion

Deploying Laravel on shared hosting isn’t as elegant as with tools like Forge or Amezmo, but it’s absolutely doable. With some tweaks and careful file organization, you can make it work reliably.


Top comments (0)