The Laravel framework is arguably one of the best backend framework out there, if not the best. But as we all know, it is not suitable to be hosted on a shared hosting account like most traditional PHP frameworks because of the advanced and premium features it supports. As a developer one has to learn to improvise and hack his way around to make things work as desired.
When working with Laravel, there are times you will be faced with the trouble of having to host it on a shared hosting account due to budget reasons, or maybe its just a side project you're experimenting with.
Most hosting providers do not allow their shared hosting users access to symbolic links a.k.a
symlink for security reasons, and that is a big issue when you try hosting your Laravel projects with them. This is because Laravel uses
symlink function to link images from the Storage directory to the public directory in order for the files to be accessible by the public.
When you try to use the
symlink functionality you will be greeted with an error message telling you that such function does not exist. When you try contacting the hosting providers they'll tell you that it was deliberately disabled for security reasons.
Well, you don't have to panic, what you should do is to change the upload location from the storage to the public directory so that you won't have to link the files again, and here is how you should go about that:
In your Laravel project, open the
config/filesystems.php file and make the following changes
'local' => [ 'driver' => 'local', 'root' => public_path('/'), 'throw' => false, ], 'public' => [ 'driver' => 'local', 'root' => public_path('/'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', 'throw' => false, ],
As you can see, all you need to do is change
public_path('/') which means our uploads will be saved to the public directory. If you wish you can change that
/ to whatever sub-directory you want them saved to. eg:
You can put whatever you like as the path inside the
public_path() method call, just configure it to suite your code, upload your files and check the public directory, and you'll find them there.
That is all, if you have any questions kindly drop it in the comments section
Top comments (0)