I'm using storage_path
to save my images and I symbolic my storage folder to public_html
php artisan storage:link
On the local everything works fine, when I upload an image it will upload in storage folder and link of it will appear in public
folder but since I moved to live host and production mode my images will upload in storage folder but nothing in my public_html/storage
and I'm not able to get them in my front-end.
Codes
/config/filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public/'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
.env
FILESYSTEM_DRIVER=public
controller sample
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'page' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($image)->resize(1200, 600)->save($location);
if(!empty($page->image)){
Storage::delete('images/' . $page->image);
}
$page->image = $filename;
}
any idea?
You also can delete your folder storage:link first then open terminal in host and command php artisan storage:link . If your hosting support symlink it will works
Solution: Once your application is uploaded to the live server. Just check that if you are having any storage folder in public directory. Check the folder stucture
Just delete the storage folder from the public directory.
After that from putty software access your main Laravel project folder, and run this command on live.
Remember to configure your .env file APP_URL={your live server ip} and then the below command.
It will create a new storage link in public folder associated with the APP_URL .
SOLVED
Thanks for all your helps, I tried to run
php artisan storage:link
on my server and I found out that my server has disabledsymlink
for security reason.So I have changed all my image uploading functions to upload images in my
public
folder instead ofstorage
folder and now everything is working just fine.delete folder storage From public and run this Command in Cron Job [ one time ]
ln -s /home/public_html/storage/app/public /home/dev5/public_html/public/storage
I just encountered this problem, and this is how I fixed it, without the need of SSH'ing into the server or running a CronJob:
For Laravel 5+ (Haven't tested with lower version)
You may use
Artisan::call()
method inside your route/controller to execute artisan commands without using the terminal.change storage_path settings by public_path
if that does not work, you can try: