Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Storage symlink

I'm trying to access files that are stored in storage/app/.../.../file.png.

I have created a symlink, linking my storage folder to public/storage.

When I try to access the appropriate file, my server throws a 404, saying file not found. Clearly I'm not accessing it the right way but I dont know what to change.

<img src="{{asset('storage/app/puppy/18/ax2Fk08nyWrV6TwTOnsXNCkNGuIdFebB7TTfPYGb.png')}}" alt="">

enter image description here

like image 660
Vranvs Avatar asked Aug 03 '18 15:08

Vranvs


People also ask

How do I link my storage to server in Laravel?

Create a symbolic link By default, public disks use local drivers and store these files under storage/app/public . To access them via the web, you need to create a symbolic link from public/storage to storage/app/public .

How do I access storage in Laravel?

Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.

What is symlink in Laravel?

Laravel Symbolic link is used to link storage/app/public directory with the public directory. The easiest way to understand Symbolic link is to think a folder shortcut which we usually create in Windows. So if we add/edit/delete anything in the shortcut folder it will also reflect on the main folder and vice versa.

How do I give permission to storage in Laravel?

Change all file permissions to 644. Change all folder permissions to 755. For storage and bootstrap cache (special folders used by laravel for creating and executing files, not available from outside) set permission to 777, for anything inside. For nodeJS executable, same as above.


2 Answers

when you create symlink in laravel then it create symlink of storage/app/public folder to public/storage folder. That means if you want to access any files publicly then place all your files inside storage/app/public folder and access it like this

<img src="{{asset('storage/puppy/18/test.png')}}" alt="">

Here it means the file test.png should be physically at storage/app/public/puppy/18 folder.

Execute php artisan storage:link for creating symlink in laravel

Hope it clear you

like image 144
rkj Avatar answered Sep 28 '22 07:09

rkj


For shared hostings try below solutions

Code:

1) Remove storage folder in public_html/public/storage

2) Create a php file for example symlink.php in public_html folder

3) Add codes to symlink.php file

$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';

4) Go to web site example.com/symlink.php

That is all...

Video url from youtube => https://www.youtube.com/watch?v=svyN8-PjGHc

like image 45
Nijat Aliyev Avatar answered Sep 28 '22 06:09

Nijat Aliyev