Upload Laravel To free / shared Hosting
Upload Laravel To free / shared Hosting

Upload Laravel To Free / Shared Hosting

Uploading a Laravel project to free or shared hosting requires a few adjustments because most shared hosting providers do not give full server access like VPS hosting.


1. Prepare Your Laravel Project

Before uploading, optimize your Laravel application on your local computer.

Run these commands:

composer install
composer update
php artisan config:cache
php artisan route:cache
php artisan view:cache

Optional optimization:

php artisan optimize

This helps improve performance and reduce loading time.


2. Configure the .env File

Edit your .env file according to your hosting configuration.

Example:

APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password

Important:

  • Set APP_DEBUG=false for security.
  • Use the database credentials provided by your hosting provider.

3. Set the Public Folder Correctly

Laravel uses the public folder as the web root.

On shared hosting:

Option 1 (Recommended)

Point your domain document root to:

/public

Example:

public_html/laravel-app/public

Option 2 (If document root cannot be changed)

Move the contents of the Laravel public folder into public_html.

Then edit index.php:

From:

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

To:

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

4. Upload Laravel Files

You can upload files using:

  • File Manager (cPanel)
  • FTP Client
  • SSH (if available)

Upload:

  • app
  • bootstrap
  • config
  • database
  • resources
  • routes
  • storage
  • vendor

Do NOT forget:

  • .env
  • .htaccess

5. Create a Database

From your hosting control panel:

  1. Create a MySQL database
  2. Create a database user
  3. Assign the user to the database
  4. Give all privileges

Then update the .env file with the correct database details.


6. Generate Application Key

If SSH/Terminal access is available:

php artisan key:generate

If not available:

  • Generate locally first
  • Copy the generated APP_KEY into the .env file

Example:

APP_KEY=base64:xxxxxxxxxxxxxxxx

7. Run Database Migration

If terminal access is available:

php artisan migrate --force

If migration is not allowed:

  • Export your local database using phpMyAdmin
  • Import it into the hosting database

8. Set Folder Permissions

Laravel needs writable permissions for:

storage
bootstrap/cache

Recommended permissions:

755 or 775

Some hosting providers may require 777.


9. Common Problems

500 Internal Server Error

Usually caused by:

  • Wrong .env
  • Incorrect permissions
  • Missing .htaccess

Vendor Folder Missing

Run locally:

composer install

Then upload the vendor folder.


Blank Page

Enable temporary debugging:

APP_DEBUG=true

After fixing the issue, change it back to:

APP_DEBUG=false

10. Final Check

After upload:

  • Open your domain
  • Test login and database connection
  • Check image upload
  • Test routes and forms

If everything works, your Laravel application is successfully deployed on free/shared hosting.