How to deploy laravel project in shared hosting

How to deploy laravel project in shared hosting

Hello readers, here we will discuss an interesting topic now, the most asked and debated question – Laravel project in shared hosting?  Some say you can and some say you should not do it. Here we will discuss when to deploy our project to shared hosting and how to deploy in shared hosting.

When to deploy in shared hosting

  • When you just completed some courses on Laravel or some tutorial on Laravel. Followed it and completed it locally. And now you want to show your project to all the people, you can opt for the cheap hosting  – shared hosting.
  • When you are maintaining a blog/site(with shared hosting) where you write posts and share your information about Laravel, in that case, if you need to show some demo of your code, you can go for shared hosting and can deploy your projects there.
  • Small applications which do not involve collecting any personal and secure information of the people like bank debit/credit card details and which does not involve any payment gateway systems.

Most of the people say shared hosting is not secure as all the accounts are hosted in the same machine. So that others might have an opportunity to sneak into your files and codebase. However, most of the shared hosting providers keeps up all the necessary security to avoid all such things. It is up to us what type of project we are hosting, as mentioned above, all sample applications, test applications, applications for demo purpose, and all small applications can be hosted but security and private data related applications are not preferred with shared hosting.

Moreover, Laravel is not designed for shared hosting providers. If one can afford a bit more, one can set up an account at $10/month at laravel forge, and also you can join Bluehost for as low as 3.95$ per month.

How to deploy in shared hosting

Saying that now let’s see how to deploy Laravel application in shared hosting.

Generally, in shared hosting all the files are present in public_html or www or something similar directory. For example assume public_html folder at /user/bob/public_html. Now follow the simple 4 steps.

  1. Create a new folder(example laravelapps) in the same location where public_html or www or whatever folder it is. (now it should be at /user/bob/laravelapps).
  2. Upload all your laravel project files/codebase to that except public folder to newly created directory laravelapps.
  3. If the shared hosting supports installing and updating the composer do it or else copy the vendor folder too.
  4. Now create another folder in public_html folder and place the contents in the public folder there. (/user/bob/public_html/testlaravel). Or can directly place the contents of the public folder in public_html folder.
  5. Change the path of
    require __DIR__.'/../bootstrap/autoload.php'; and
    $app = require_once __DIR__.'/../bootstrap/app.php';
    require __DIR__.'/../laravelapps/bootstrap/autoload.php'; and
    $app = require_once __DIR__.'/../laravelapps/bootstrap/app.php';

    in index.php file located at the public directory. If you have multiple projects uploaded to /user/bob/laravelapps you can change index file as,
    require __DIR__.'/../laravelapps/project_name/bootstrap/autoload.php'; and
    $app = require_once __DIR__.'/../laravelapps/project_name/bootstrap/app.php';

Make sure you upload all the files in a public folder including .htaccess file and make sure your routes are correct in routes.php file.

Now, Laravel project which is deployed on shared hosting can now be accessed at if public directory contents are placed in testlaravel folder or at if public directory contents are placed directly in public_html folder.

Feel free to browse some previous tutorials on bootgrid implementation, sending emails using sendgrid, visualization of data using highcharts.

2 thoughts on “How to deploy laravel project in shared hosting”

  • 1
    Sofiene Meksi on April 20, 2017 Reply

    Think of the symlink to the storage

  • 2
    Oliver Russell on August 11, 2017 Reply

    I wouldn’t recommend a shared hosting for Laravel app. Shared hosting is not good in terms of performance and security. The only good thing about shared hosting is that it is cheap. If you want to trade off performance and security against cost, then go ahead. Otherwise, avoid shared hosting. A better alternative is a VPS, like DigitalOcean. If you don’t know how to setup a Laravel server, then you can try out Cloudways platform ( ). This platform automatically setups the server with OS and stack.

Leave a Reply