Back

how to Setup Laravel 5 in Shared Hosting


how to Setup Laravel 5 in Shared Hosting ?

astroanu replied 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.

tatianilima replied 2 years ago

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?

sukonovs replied 2 years ago

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.

itarafath replied 2 years ago

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

Kyslik replied 2 years ago

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

pitagora04 replied 2 years ago Solution

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..

pitagora04 replied 2 years ago

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

itarafath replied 2 years ago

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?

pitagora04 replied 2 years ago

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..

itarafath replied 2 years ago

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

ricksonchew replied 2 years ago

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>
astroanu replied 2 years ago

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.

Ziecs replied 2 years ago

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

luciddreamz replied 2 years ago

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.

astroanu replied 2 years ago

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 ?

yaniksilver replied 2 years ago

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.

mitacliff replied 2 years ago
<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

idesignedme replied 2 years ago

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

poentes replied 2 years ago

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!

getupkid203 replied 2 years ago

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..

percyimm replied 2 years ago

itarafath said:

how to Setup Laravel 5 in Shared Hosting ?

This is a good option , supports laravel May from $ 3.5 / month www.hostinglaravel.com/planes.php

itmanvn replied 2 years ago

Another working solution: https://medium.com/@kunalnagar/deploying-laravel-5-on-godaddy-shared-hosting-888ec96f64cd

hoshomoh replied 2 years ago

I recently wrote an article on how I was able to host my laravel on a shared host. http://www.stuckcoders.com/how-to-host-your-laravel-project-in-a-shared-hosting/

luanntvn replied 1 year ago

Below are steps I've set on a hosting with cPanel without any changes in laravel_app:

  1. check out/copy laravel_app code to your home, /home/your_user/laravel_app

  2. set permissions:

chmod 755 /home/your_user/laravel_app/ chmod 755 /home/your_user/laravel_app/public/ chmod 644 /home/your_user/laravel_app/public/index.php chmod -R 777 /home/your_user/laravel_app/storage

  1. create symlink ln -s /home/your_user/laravel_app/public ~/public_html/laravel_app_public

  2. create ~/public_html/.htaccess following hoshomoh's instruction

Options -Indexes

RewriteEngine On RewriteCond %{REQUEST_URI} !^/laravel_app_public/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ laravel_app_public/$1 RewriteRule ^(/)?$ laravel_app_public/index.php [L]

NicolasVanhecke replied 1 year ago

How do you disable varnish cache in the .htaccess ??

One.com (shared host) keeps sending me this:
You add one line in your htaccess file in the root directory with only this "disablevcache" "true"
But suprise suprise, this does not work... !!
Is this meant to be in the .htaccess in the root folder??? And where do you put it if THIS is your .htaccess so far...

<IfModule mod_rewrite.c> RewriteEngine On

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

Thanks

seejaykay2016 replied 1 year ago

ricksonchew said:

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>
seejaykay2016 replied 1 year ago

This was simple and worked on Dreamhost for me.

saadsaleem187 replied 9 months ago
  1. First make zip of your project.

  2. Upload it to the public_html or www according to your hosting.

  3. Extract it. Open your project.

  4. Move all files from public folder to your project main folder.

  5. Open index.php file. Change below two lines.

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

to this

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

6 Open server.php. Change below two lines

if ($uri !== '/' && file_exists(__DIR__.'/public/'.$uri))      
require_once __DIR__.'/public/index.php';

to this

if ($uri !== '/' && file_exists(__DIR__.'/'.$uri))
require_once __DIR__.'/index.php';

7 Open .htaccess file. Replace all with below lines

 DirectoryIndex index.php

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RedirectMatch 404 /\.git

RewriteEngine On

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

RewriteRule .? %{ENV:BASE}/index.php [L]

</IfModule>

8 Open .env file. Change

    APP_URL=http://localhost 

to this

    APP_URL=yourdomain
avinashn replied 9 months ago

You can follow this step by step guide here. It's almost same as the solution accepted, but it would be more clear if we can refer a blog post on it http://justlaravel.com/how-to-deploy-laravel-project-shared-hosting/

percyimm replied 6 months ago

HOSTING LARAVEL 5.4 PHP 7 Shared Hosting It offers web hosting for your projects in Laravel Framework all versions (4.x up to 5.4), we have support for PHP versions 5.3, 5.4, 5.5, 5.6, 7.0 and 7.1, up to 20 times faster thanks to the storage technology SSD. Http://hostinglaravel.com/

kevosomi replied 5 months ago

Hey Guys,

This is a probably very late solution but I hope it will help someone in future. Create a .htaccess and place the file in your laravel root directory. Then paste the following and save. It should solve all the problems regarding shared hosting and 404's being thrown when visiting any other pages apart from the homepage.

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.codestudio.club/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: [email protected]

  ErrorDocument 404 /index.php
</IfModule>
gauravojha replied 5 months ago

Probably a very late reply but may help others. I followed the same method as @luanntvn about the symlink process and in my opinion is the simplest approach for deploying a laravel application on a shared hosting. I had no problems in hosting my application and it runs great.

Ana Liza Bongat replied 2 months ago

@kevosomi it works but not on all pages, it does not retrieve requested data..


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us