Skip to main content
Tutorial Free

Laravel Public Files with No Symlink: in Public Folder Instead of Storage

July 17, 2023
2 min read

By default, Laravel stores the uploaded public files in the storage/app/public, and you should create a so-called "symbolic link" with the Artisan command "php artisan storage:link". But what if you don't have SSH access to the Terminal and can't run this command?

One of the solutions is to store the public files in the /public folder without any storage/ or symlinks.

To do that, you need to change the configuration of your local public disk.

config/filesystems.php:

'disks' => [
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
'throw' => false,
],

Then you could use this command to access the files in public/images, for example:

$path = $request->file('avatar')->store(
'images/something.png', 'public'
);

That file will be stored in public/images/something.png.

Assuming your web-server document root is correctly set to the public/ folder, you can access that file as https://yourwebsite.com/images/something.png.

Notice: be careful not to override the default files that come with Laravel in the /public folder. Make sure to always create subfolders for your custom uploaded files.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.