Where are you storing them?
laravel 9 storage not working
I created my site on shared hosting with laravel 9.but my dynamic placed photos are not loading.i don't have terminal access.when i open photos in new tab i get 404 error
@Sinnbeck example: public_html>storage>app>public>icon>icon.png public_html>storage>app>public>gallery>gallery.png
@urwxgrwx ok for that to work you need to run storage link. If you don't have shell access you can try calling this from a route
Artisan::call('storage:link');
@Sinnbeck I think I need to write this route I tried but it didn't work
@urwxgrwx if it works you should see the folder public_html/public/storage show up
@Sinnbeck there is only storage shortcut in my public folder.so it may not be working?
@Sinnbeck I created and went to the link but 500 I got SERVER ERROR error example Route::get('/linkstorage', function () { Artisan::call('storage:link'); });
@urwxgrwx did you import artisan at the top of the file? I recommend testing it locally first
@Sinnbeck yes i tried it directly on cpanel. do i need to do it locally and reload the project?
Storage shortcut? So are the files inside of that folder?
@Sinnbeck no. public_html>public>storage shortcut. not have public >storage
@urwxgrwx directly on cpanel? You can run artisan commands from there? Or do you just mean on the server?
No you cannot make the symlink locally and upload it. If you did upload the /public/storage folder then you need to delete it on the server and recreate it with storage:link (on the server)
@Sinnbeck just mean server.I created the symlink you said on the server but not working.sorry for the confusion.I don't have terminal access on cpanel.is there any other solution? :(
@urwxgrwx how did you make the symlink? Is there a button for that on cpanel or? (I have never used cpanel)
@Sinnbeck I created symlink.php in public_html into
Route::get("/storage-link", function () {
$targetFolder = storage_path("app/public");
$linkFolder = $_SERVER['DOCUMENT_ROOT'] . '/storage';
symlink($targetFolder, $linkFolder);
});
I wrote and went to the link
@urwxgrwx so if you open /public/storage you see your files there? Or is it empty?
@Sinnbeck A storage shortcut has been created in public, so I can see it locally, but the shortcut is not visible in cpanel.
@urwxgrwx hmm maybe someone here knows cpanel and how to see if it was created.
Can you show the output of
$linkFolder = $_SERVER['DOCUMENT_ROOT'] . '/storage';
dd($linkFolder);
Maybe try it like this
$linkFolder = public_path('storage');
$linkFolder = $_SERVER['DOCUMENT_ROOT'] . '/storage';
dd($linkFolder);
output:
^ "/home/konyayal/public_html/storage"
$linkFolder = public_path('storage');
dd($linkFolder);
^ "/home/konyayal/public_html/public/storage"
@urwxgrwx second one seems correct. They again with that version
@Sinnbeck now web.php into add
Route::get("/storage-link", function () {
$linkFolder = public_path('storage');
});
/storage-link
didn't give an error.it just gave blank white page. but nothing seems to have changed
@urwxgrwx did you forget the rest of the code?
Route::get("/storage-link", function () {
$targetFolder = storage_path("app/public");
$linkFolder = public_path('storage');
symlink($targetFolder, $linkFolder);
});
@Sinnbeck it doesn't work that way.500 server error.
Route::get("/storage-link", function () {
$linkFolder = public_path('storage');
symlink($linkFolder);
}); again 500 server error
@urwxgrwx check your server logs to see what error that was :) or /storage/logs/laravel.log
@Sinnbeck I think I'm making a mistake in writing symlink $linkfolder on phpstorm looks wrong. laravel.log [2022-09-29 08:57:24] local.ERROR: Call to undefined function symlink() {"userId":3,"exception":"[object] (Error(code: 0): Call to undefined function symlink() at /home/konyayal/public_html/routes/web.php:48) [stacktrace]
@Sinnbeck [2022-09-29 09:01:46] local.ERROR: Call to undefined function symlink() {"userId":3,"exception":"[object] (Error(code: 0): Call to undefined function symlink() at /home/konyayal/public_html/routes/web.php:52) [stacktrace]
symlink($targetFolder, $linkFolder); line 54
@urwxgrwx Sounds like your host have disabled the symlink command. Contact them and ask them to enable it :)
@Sinnbeck Is it because it's shared hosting?
@urwxgrwx Yeah that could very well be. But try asking your provider. Maybe it is just disabled by default, and they can enable it for you
https://laracasts.com/discuss/channels/laravel/laravel-on-shared-hosting-6
maybe you can try that solution
Are you using a symbolic link? If so, try this!
https://www.youtube.com/watch?v=svyN8-PjGHc&ab_channel=NijatAliyev
Please or to participate in this conversation.