Skip to main content



How to Host a Laravel Application on Shared Hosting

How to Host a Laravel Application on Shared Hosting

Laravel is one of the most popular PHP frameworks in the world, renowned for its elegant syntax, robust features, and developer-friendly tooling. However, many developers encounter a common challenge: deploying a Laravel application to a shared hosting environment. Unlike a VPS or dedicated server, shared hosting comes with certain restrictions that can make the process feel daunting. The good news is that Laravel shared hosting deployment is entirely achievable with the right approach. In this guide, we will walk you through every step of the process clearly and methodically.

Why Host Laravel on Shared Hosting?

Shared hosting is often the most affordable entry point for individuals and small businesses looking to get their web applications online. Whilst a VPS offers more control, shared hosting plans from providers such as Hostinger, SiteGround, or Bluehost are significantly cheaper and require far less server administration knowledge.

The trade-off is that shared hosting environments are more restrictive. You typically do not have root access, and you may not be able to install software globally. Nevertheless, most modern shared hosting providers support PHP 8.x, MySQL, and even SSH access, which is all you really need to run a Laravel application successfully.

Prerequisites Before You Begin

Before diving into the deployment process, make sure you have the following in place:

  • A shared hosting account with PHP 8.0 or higher support
  • SSH access enabled on your hosting account (strongly recommended)
  • A MySQL database created via your hosting control panel (cPanel or equivalent)
  • Composer installed or accessible on the server
  • Your Laravel project ready and tested locally
  • An FTP client such as FileZilla, or access to a file manager

If your hosting provider does not support SSH access, the process becomes more manual, but it is still possible. We will cover both scenarios below.

Understanding the Laravel Directory Structure for Shared Hosting

One of the most important things to understand about Laravel shared hosting deployment is how the directory structure works. Laravel has a public folder that serves as the web root. Your shared hosting account will typically have a public_html folder (or similar) where all publicly accessible files must reside.

The challenge is that the rest of your Laravel application — including your .env file, app directory, config folder, and other sensitive files — should never be publicly accessible. This requires a specific setup to ensure security and functionality.

The Recommended Folder Structure

The cleanest approach is to upload your entire Laravel project one level above the public_html directory, and then point the public_html folder to Laravel’s public directory. Here is how the structure should look on your server:

  • home/yourusername/laravel-app/ — Your full Laravel project lives here
  • home/yourusername/public_html/ — This should contain the contents of Laravel’s public folder

By keeping the application files outside the web root, you protect sensitive configuration data from being accessed directly via a browser.

Step-by-Step Guide to Deploying Laravel on Shared Hosting

Step 1: Upload Your Laravel Files

Using an FTP client or your hosting provider’s file manager, upload your entire Laravel project to a directory outside of public_html. You can name this folder something like laravel or myapp. Ensure all files and folders are transferred, including hidden files like .env.

Step 2: Move the Public Folder Contents

Next, copy the contents of your Laravel public folder into the public_html directory. Do not move the entire folder — just its contents, including index.php, the .htaccess file, and any compiled assets.

Step 3: Update the index.php File

Once the contents of the public folder are inside public_html, you need to update the paths in index.php so that Laravel can locate the rest of the application. Open the index.php file and update the following lines:

Change:

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

To reflect the actual path to your Laravel project:

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

Make sure the path matches exactly where you uploaded your Laravel files on the server.

Step 4: Configure Your .env File

Your .env file contains all the critical configuration for your application, including database credentials, application key, and environment settings. Update the following values to match your shared hosting setup:

APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.co.uk

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password

Ensure APP_DEBUG is set to false in a production environment to prevent sensitive error information from being displayed publicly.

Step 5: Install Dependencies via Composer

If your hosting provider allows SSH access, connect to your server and navigate to your Laravel project directory. Run the following command to install all dependencies:

composer install --optimize-autoloader --no-dev

If SSH is not available, you will need to run composer install locally and upload the entire vendor folder via FTP. This is not ideal due to the large number of files, but it works as a last resort.

Step 6: Set the Application Key

If you have not already generated an application key, do so via SSH with:

php artisan key:generate

This will automatically update your .env file with a unique key. If you cannot use SSH, generate the key locally and manually copy the value into your .env file on the server.

Step 7: Run Database Migrations

With SSH access, you can run your migrations directly:

php artisan migrate --force

Without SSH, you will need to use a tool like phpMyAdmin to manually import your database schema using an SQL export from your local environment.

Step 8: Set File Permissions

Laravel requires write access to certain directories. Using SSH or your file manager, set the appropriate permissions:

chmod -R 775 storage bootstrap/cache

This ensures Laravel can write logs, cache files, and session data without encountering permission errors.

Common Issues with Laravel Shared Hosting

500 Internal Server Error

This is one of the most common errors encountered during deployment. It is usually caused by incorrect file paths in index.php, missing .env file, or incorrect file permissions. Enable temporary debugging by setting APP_DEBUG=true to identify the root cause, then disable it once resolved.

Composer or PHP Version Conflicts

Some shared hosting providers run older versions of PHP by default. Check your hosting control panel for PHP version switcher options and ensure you are running at least PHP 8.0. For further reading on managing hosting environments and tools, visit da-manager.com/blog for helpful guides and resources.

Missing .htaccess File

If your URLs are not working correctly, it is likely that the .htaccess file is missing from public_html. Ensure it has been transferred correctly and that mod_rewrite is enabled on your server. You can confirm this with your hosting provider’s support team.

Tips for Optimising Your Laravel Application on Shared Hosting

Once your application is live, consider running the following Artisan commands to improve performance:

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

These commands cache your configuration, routes, and views, reducing the number of file reads on each request and noticeably improving response times in a shared hosting environment.

Final Thoughts

Deploying a Laravel application to shared hosting requires careful planning and a clear understanding of how the framework’s directory structure interacts with your server’s web root. By following the steps outlined in this guide, you can successfully get your Laravel shared hosting deployment up and running without needing an expensive VPS or dedicated server.

Whilst shared hosting does have its limitations, it remains a perfectly viable option for small to medium-sized Laravel applications, especially during the early stages of a project. With the right configuration, your application will be secure, functional, and ready to serve your users reliably.