Laravel deployed to shared hosting not displaying image - laravel

I deployed a laravel app to shared hosting (hostinger). Everything is working fine except the images which are not showing up.
I have created a symlink of my storage folder with my public_html folder. Files uploaded enters the public folder but when I link the images they still do not show up.
I have created a symlink to the public_html since I cannot access the public folder. I need help on this please
I need the image to be displayed on the browser

In default Laravel deployment the symlink is created in public folder as storage and links to ../storage/app/public.
In order to debug your problem, please have a look at the developer tools of your browser to find out whether it is a 404 or 403 problem (or even another).
Please check for correct permissions. Otherwise you may change the physical storage path to something inside the public folder. This avoids the requirement to create a symlink. Keep in mind to protect non-public storage via .htaccess for example.

You have to the path to your public assets directory if it is not public directory in the root folder. In your case, the public assets directory is public_html. So please bind the path to it from the root folder.
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* #return void
*/
public function register()
{
if (App::environment('prod')) {
$this->app->bind('path.public', function() {
return base_path('../../public_html');
});
}
}
}

had the same problem, remember to run 'php artisan config:cache' as per Laravel Deployment guidelines.
Running the command creates a general configuration file
in app/bootstrap/cache/config.php with all settings including directories and links that you should update

Related

Path for images for Laravel project from cpanel

I have a problem with displaying pictures in View for my project in Laravel..destination path in my application where the photos were saved is: public_path (/ images) but recently I put the project on the server in cpanel, and to get rid of / public from the url, I used a google article, and I made a folder called laravel outside the public_html folder, in which I keep the application files and in public_html I keep only the files that were in the public folder of the application. In View I display the pictures as follows: "{{asset ('images /'. $ Img-> file_name)}}" .. Only it is no longer displayed. Pictures are saved but no longer displayed. I mention that it is saved in the Laravel folder which is outside the public_html folder..and I think that public / images was created automatically there..I would like to know if anyone has faced such a thing and what is the solution. thank you
I solved the problem like this:
In AppServiceProvider in register() I put this code:
$this->app->bind('path.public', function () {
return base_path('../public_html');
});
and now I have public_html/images and there my images are saved..and the rest of myy app, outside public_html folder in a different folder named laravel_project
In Laravel 8, I solved it adding this to the /app/Providers/AppServiceProvider.php in register method:
public function register()
{
$this->app->bind('path.public', function () {
return base_path('../public_html');
});
}
But in order to create the symlink from the "php artisan storage:link" command, I also had to add this code to /bootstrap/app.php, just after the last singleton:
$app->bind('path.public', function () {
return base_path("../public_html");
});
Finally I used this code to get the image that will be sent to my blade template:
$image=Storage::disk('public')->url('path_to_image');

Laravel image cache using Dropbox as disk

I'm using this package (https://github.com/spatie/flysystem-dropbox) to storage and get images from Dropbox.
This works fine but images have to load everytime the page is refreshed. I wonder if you know any image cache solution that works in this case and if can please provide with a minimal working example.
Thanks.
One way to solve this would be to create your own caching system. If the image doesn't exist on your local file system, pull it from Dropbox and then save it to the local file system and serve it. If it already exists in the local file system just serve it from the local file system.
1 Route
Serve the images from their own route.
Route::get('images/{filename}', [
'uses' => 'ImageController#getImage'
]);
2 Controller
Check the local file system to see if the file already exists, otherwise pull it from dropbox and store it in the local file system.
<?php
namespace App\Http\Controllers;
class ImageController extends Controller
public function __construct()
{
parent::__construct();
}
public function getImage($filename)
{
// If the file doesn't exist
if(!file_exists('/path/to/' . $filename)) {
// 1. Get the image from dropbox
// 2. Save the image to local storage
}
// 3. Serve the image from local storage
}
}

How to change the symbolic link in development env shared hosting laravel?

I have a Larevel-app in a shared hosting. For the setup, I had to create a new folder in the main carpet of the hosting and copy the content of my public folder to public_html. I made changes in index.php and all working fine and nice. However, when a user upload a file that needs to be public, this file it saved in the myproject/storage/app/public path but not reflected in the public_html/storage so I can't access to it.
Reading the documentation, I know it is a problem with the symbolic link.
how can I change it?
Note: I can't access to the cdm because it is a shared hosting without access. It is window hosting.
make this route in web.php then hit this
Route::get('/artisan/storage', function() {
$command = 'storage:link';
$result = Artisan::call($command);
return Artisan::output();
})

Laravel Route to Standalone WebApp

I am trying to build a portal in Laravel to serve some other, standalone web apps (not built in Laravel), but I am struggling to find out how to route to these apps if I want to place them outside the public folder.
In the past, I would use (temporary) symlinks for this kind of things, but I was wondering if Laravel provides another solution.
So, I have a folder:
module
module/index.php
module/js/whatever
module/css/whatever
module/img/whatever
and I want a route /modules/1 to link to index.php in the module-folder in such a way that the resources in this folder (js/css/img) are also accessible.
Any suggestions?
You can include other PHP files with require_once.
web.php
Route::any('/webapp/{assets?}', 'WebAppController#index');
WebAppController
class WebAppController {
public function index(Request $request) {
require_once '../module/index.php';
if ($request->assets) {
// check from session if user is logged in
// require asset as well
// (or download them https://laravel.com/docs/5.5/responses#file-downloads)
}
}
}
http://php.net/manual/en/function.require-once.php

Laravel 4 installation on server not working

Hello I have installed laravel 4 on my server, the installation was done from cpanel , I get the default welcome message of Laravel on this link http://www.mysite/laravel/public
I added a controller and a view and I tried to run the url for that new controller and I get a Error 404 - Not Found
The document you are looking for may have been removed or re-named. Please contact the web site owner for further assistance.
This is what I did after laravel was installed :
TestController.php
<?php
class TestController extends BaseController {
public function index()
{
return View::make('index');
}
}
routes.php
Route::get('/Test', function()
{
return View::make('index');
});
views/index.php
<h1>Test</h1>
am I doing something worng?
here is my folder structure :
I had a similar problem when deployed my project on a host the first time.
You should put all the content of your public folder in the pre-existing public or public_html folder and the whole app folder in the root folder of the server.
Then you change app/config/app.php to tell the new path of app to laravel, and change your .htaccess file to point the document root to the new public folder.
This worked for me, if you need additional details, ask.

Resources