Deploy your Laravel 5 App in shared hosting

indexOnce again, I had to make my hand dirty. This time I had to deploy Laravel 5 application in a shared hosting. Laravel framework’s architecture is not designed to deploy in shared hosting. So, if you want to deploy in shared hosting of cource you will have to hack the framework.

I will not recommend anyone to do this hacking unless you don’t have any other options. Because there are couple of cheap solutions in the market. You can go for DigitalOccean, Amazon AWS or any cheap VPS services. Some of them has dedicated services for Laravel framework such as Cloudways and OpenShift. Whatever, I am not here to market about their products. I just want to help you out that what hacks you need to do to run the Laravel 5 application in shared hosting. Basically, you will have to change two files.

First, you will have to copy all files from laravel/public to root folder (for shared hosting it is public_html). Then, it will have to update the following paths inside the index.php
At line 21

From: require __DIR__.'/../bootstrap/autoload.php';
Change to: require __DIR__.'/bootstrap/autoload.php';

At line 35

From: $app = require_once __DIR__.'/../bootstrap/app.php';
Change to: $app = require_once __DIR__.'/bootstrap/app.php';

Second, you will have to update server.php file.

From:
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri))
{
	return false;
}
 
require_once __DIR__.'/public/index.php';
Change to:
if ($uri !== '/' && file_exists(__DIR__ . $uri)) {
	return false;
}
 
require_once __DIR__.'/index.php';

Expecting, this one helps you out to deploy your Laravel 5 applicaiton in dirty way. Happy hacking 🙂

 

Eftakhairul Islam

Hi, I'm Eftakhairul Islam, a passionate Software Engineer, Hacker and Open Source Enthusiast. I enjoy writing about technical things, work in a couple of startup as a technical advisor and in my spare time, I contribute a lot of open source projects.

 

6 thoughts on “Deploy your Laravel 5 App in shared hosting

  1. I have uploaded my project into a folder called “laravel” in public_html.
    Then I copied the contents of public folder into public_html and changed the index.php and server.php as you said. Here is the error log:
    [07-Oct-2015 19:30:45 UTC] PHP Warning: require(/home/motarjem/public_html/bootstrap/autoload.php): failed to open stream: No such file or directory in /home/motarjem/public_html/index.php on line 22
    [07-Oct-2015 19:30:45 UTC] PHP Warning: require(/home/motarjem/public_html/bootstrap/autoload.php): failed to open stream: No such file or directory in /home/motarjem/public_html/index.php on line 22
    [07-Oct-2015 19:30:45 UTC] PHP Fatal error: require(): Failed opening required ‘/home/motarjem/public_html/bootstrap/autoload.php’ (include_path=’.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php’) in /home/motarjem/public_html/index.php on line 22

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Read previous post:
gisbn Ruby GEM

The best way to sell yourself and get exposer as a new developer is contributing to open source projects either...

Close