Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 on shared hosting - wrong public_path()

I deployed a Laravel 5 project to a shared hosting account, placing the app-files outside of the www-folder, placing only the public folder inside of the www-folder. All like explained here, in the best answer: Laravel 4 and the way to deploy app using FTP... without 3. because this file doesn't exist in Laravel 5.

Now when I call public_path() inside of a controller i get something like my-appfiles-outside-of-www/public instead of www/public. Does anyone know why I doesn't get the right path here? Can I change this somewhere? Thanks!

like image 824
johnnydoe82 Avatar asked Apr 27 '15 09:04

johnnydoe82


2 Answers

You can override public_path using container. Example:

App::bind('path.public', function() {
    return base_path().'/public_html';
});
like image 102
mcklayin Avatar answered Sep 22 '22 22:09

mcklayin


$app->bind('path.public', function() {
  return __DIR__;
});

write above code in public_html\index.php above of this code

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
like image 4
Mahdi mehrabi Avatar answered Sep 22 '22 22:09

Mahdi mehrabi