how to Setup Laravel 5 in Shared Hosting

how to Setup Laravel 5 in Shared Hosting ?

itarafath
itarafath
  • 2 years ago

There's nothing special. you need to copy all the files to the server. You can write a gulp task to do this. I'm using something like that with vinyl ftp. works perfectly.

doesn't work copy all files to server. I have tried, but I received error 500.

I cannot find the file bootstrap/paths in laravel 5 Maybe I need change the path in index.php...

I don't know how to begin..

Anybody help me?

Laravel is not designed to work on shared hosting providers. You can hack up framework of cource but I dont recommend it.

Nowdays SSD hostings are cheap. With forge it is possible to set up server for 15$/m easy.

However. I installed laravel 4 in shared hosting.5 wont work/

Tell your admins to make root /public and you are good to go.

Hi, I would like to use Laravel 5 on shared hosting. I use SSH connection to my user folder. I installed composer successfully. Then I run "php composer.phar create-project laravel/laravel laravel --prefer-dist" and that was fine (I just had to enable proc_open before). Ok, the next step should be redirecting public folder and here I have problems. I copied all files from laravel/public to public_html.

Then I corrected paths in public_html/index.php:

require DIR.'/../laravel/bootstrap/autoload.php';

$app = require_once DIR.'/../laravel/bootstrap/app.php';

When I open the site in browser I get this error: PHP Catchable fatal error: Argument 2 passed to array_first() must be callable, integer given, called in /home/myuser/laravel/storage/framework/compiled.php on line 1446 and defined in /home/myuser/laravel/vendor/laravel/framework/src/Illuminate/Support/helpers.php on line 134

What now ? Please, help.. I'm so close to make it work..

Ok, I think that I found the solution for my question: ini_set('eaccelerator.enable', 0); should be added to index.php

pitagora04 said:

Ok, I think that I found the solution for my question: ini_set('eaccelerator.enable', 0); should be added to index.php

Did you got the solution?

My procedure for installing Laravel 5 on shared hosting with Apache and cpanel

  1. connect to hosting via SSH

  2. install composer

  3. in cpanel open Select PHP version and choose 5.4. (I also set phar extension)

  4. install laravel: php composer.phar create-project laravel/laravel myproject --prefer-dist

  5. copy everything from myproject/public to public_html

  6. open public_html/index.php and set:

    require DIR.'/../myproject/bootstrap/autoload.php';

    $app = require_once DIR.'/../myproject/bootstrap/start.php';

and put this on top:

ini_set('eaccelerator.enable', 0);

Hope this could help somebody..

its worked for only home page.other pages doesn't work.may problem with .htaccess.

I've tried it on my shared hosting. Here's what I did.

  1. Install and setup laravel on your local (meaning you local machine)

  2. Once done, copy all files to your hosting.

  3. Create an .htaccess file on your laravel's root directory. This is to access it without the "public" on the url.

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_URI} !^public

RewriteRule ^(.*)$ public/$1 [L]

</IfModule>

I received error 500. means an error on the server.

Of course you need to do some configuring. check your laravel logs. The error should be there. probably a missing php extension or your htaccess file is not properly configured. set your app debug mode to true temporally laraval will throw the error.

Hi,

Finally I did the job on my shared hosting (I use Bluehost)... This is what I did

  • 1.- Setup a project Laravel 5 in localhost correctly configured
  • 2.- Double check the server configuration of PHP 5.4 (this because every little change on .htaccess file may change that config)
  • 3.- Create a directory in the same level of public_html and put the project inside of that folder.
  • 4.- Put the content of public (L5) directly on public_html (be aware of don't overwrite the .htaccess file accidentally)

Now... This is the "tricky part"... actually not xD In Bluehost I see this structure

  • mail
  • perl5
  • php
  • public_html
  • [framework-folder]
  • ssl

Inside of public_html I can see all the files of public directory of Laravel 5

Go to index.php and edit the line 22

#From this
require __DIR__.'/../bootstrap/autoload.php';
#To this
require __DIR__.'/../[framework-folder]/bootstrap/autoload.php';

And the line 36

#From this 
$app = require_once __DIR__.'/../bootstrap/app.php';
#To this
$app = require_once __DIR__.'/../[framework-folder]/pulcro/bootstrap/app.php';

The final step is to edit the .htaccess file and add some lines

RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_URI} !^
RewriteRule ^(.*)$ /$1 [L]

Refresh the cache of my browser and.. Victory!!

I know that this is not the absolute right way to install the framework (God, I never spoke about Composer)

But... It's working for me now

Hope that this can help somebody in order to deploy Laravel 5

Regards

I was running into similar issues running Laravel 5 on shared hosting. I had better luck running Laravel on OpenShift Online.

I put together a QuickStart if anyone is looking for an easy/free way to get Laravel up and running: Laravel 5.0 on OpenShift

Check out the README on GitHub for the ins/outs of local/remote deployment, debugging, running migrations, etc.

Oh i see now. Was laravel installed on the server using a command from cpanel or something? how did it go in to the framework directory ?

I would never recommend shared hosting for Laravel because of its security issues that the server faces.

Shared servers are usually prone to hacking attacks and if any malicious activity occurs, it effects whole network of websites using the server. Plus, you might experience resource limitation as everybody else in the network uses the same CPU, memory and hard drive. Or your server may get swamped by requests or overloaded which might cause it to stop.

So I believe dedicated hosting is a better choice than hosting a Laravel app on shared server. I would highly recommend Cloudways.

I have recently started my project on Laravel 5 there. Created my server on DigitalOcean in just 7 minutes with pre-installed Laravel 5.0.4 Laravel 5.0.4.

There also provide Google Compute Engine and Amazon AWS servers.

<p>if you do not have SSH access do the following:</p>

<p>1. empty the content of publics directly on your project folder</p> </p>2. Edit index.php now in your-project/index.php and not your-project/public/index.php </p>

from require DIR.'/../bootstrap/autoload.php'; to require DIR.'/bootstrap/autoload.php';

from $app = require_once DIR.'/../bootstrap/app.php';

to $app = require_once DIR.'/bootstrap/app.php';

  1. Edit server.php

from

if ($uri !== '/' && file_exists(DIR.'/public'.$uri)) { return false; }

require_once DIR.'/public/index.php';

to

if ($uri !== '/' && file_exists(DIR.'/'.$uri)) { return false; }

require_once DIR.'/index.php';

that's all...now you can access your project from localhost/your-project

I can see the welcome Zen greeting page but if I try to navigate to another page I get a 404 error. Im using laravel 5 and I'm on hostgator

So, I've been having this problem for a while but I just figure out how to solve thanks to ricksonchew's comment.

The shared hosting site I use is: https://byethost.com/
The Laravel version is: 5

After uploading my project(40 mins), I created 2 .htaccess files and each one has a purpose.

I pasted the .htaccess file to the public directory.

This is what it should be written in the file:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I also added another .htaccess to the root laravel project directory:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

The explanation is simple, if you've noticed, the first file gets rid EXCLUSIVELY of the "index.php" path, you can add an then test by yourself. The second .htaccess gets rid of the "public" path, then hen you type in the domain name, these files probably will solve the problem for you!

Hi pitagora04, Thanks for your post. Just wondering... how did you enable proc_open through ssh?

Cheers

pitagora04 said:

Hi, I would like to use Laravel 5 on shared hosting. I use SSH connection to my user folder. I installed composer successfully. Then I run "php composer.phar create-project laravel/laravel laravel --prefer-dist" and that was fine (I just had to enable proc_open before). Ok, the next step should be redirecting public folder and here I have problems. I copied all files from laravel/public to public_html.

Then I corrected paths in public_html/index.php:

require DIR.'/../laravel/bootstrap/autoload.php';

$app = require_once DIR.'/../laravel/bootstrap/app.php';

When I open the site in browser I get this error: PHP Catchable fatal error: Argument 2 passed to array_first() must be callable, integer given, called in /home/myuser/laravel/storage/framework/compiled.php on line 1446 and defined in /home/myuser/laravel/vendor/laravel/framework/src/Illuminate/Support/helpers.php on line 134

What now ? Please, help.. I'm so close to make it work..