Laravel storage symlink on shared hosting - laravel

I'm having problem with setting up storage link on shared hosting.
Because of that I can't load any image from storage folder.
My public folder is renamed to web and when I try this:
ln -s storage/app/public/ web/storage
my issue still remains. Also, I have access to the console on the server.
Any help would be appreciated
** Edit -> everything worked fine on localhost (before moving to production)

The problem was with badly linked symlink.
All I had to do was:
ln -sfv ../storage/app/public/ storage from web directory

Related

Storage symlink doesn't work with Laravel and Vue in Namecheap CPanel (LiteSpeed)

I am trying to access my image files stored inside storage/app/public/subfolder/ using symlink inside /public folder in my Laravel app. Everything works fine in my local setup and also in Jelastic Apache deployment, but it doesn't seem to work in CPanel with LiteSpeed. I am trying to access the files using the link /storage/subfolder/image.png but it is not accessible on CPanel deployment.
I tried creating and deleting storage symlink hundreds of times, but it didn't work. Below are few things I tried:
Deleting and creating symlink again and again using php artisan storage:link command.
Creating symlink using linux command ln -s ../storage/app/public storage inside public folder.
Running Artisan::call('storage:link') using a web route entry.
Redeploying and reconfiguring the app several times and creating storage symlink.
In all of these failed attempts I can verify that storage symlink is created every time inside public folder. I can navigate and view files from public/storage/ folder using CPanel terminal without any issues but can't access them in the deployed app.
I have exact same configuration in Jelastic Apache deployment and in my local deployment and there it is working without any issues.
UPDATE:
Additionally, I tried creating a storage directly manually inside public folder with the same structure and it worked. But symlink doesn't work.
UPDATE 2:
I found below error log while checking error logs from CPanel.
2022-11-06 05:07:07.342556 [ERROR] [1669834] [T0] [HTAccess] Failed to open [/home/user/my-project/public/storage/subfolder/.htaccess]: Permission denied
There is no .htaccess inside subfolder but it is there in my public folder.
What might be the issue?
After making linking you storage to your public path using storage:link you can access your folder :
'Storage_path('subfolder/image.png');'
After a long search, I finally found the cause.
Somehow the storage/app/public directory didn't have sufficient permissions. So, I gave permissions to that public folder recursively using chmod and everything works fine now.
The symlink was working fine but it was not working due to permission issues in the parent folder.
This is a bit weird as I have never manually altered permissions in any Laravel folders in any of my other deployments.

Laravel 5.6 symlink issues, 404 Not Found, but path actually exists

I recently deployed my Laravel application to a shared hosting server with ssh access, on my local machine every thing worked perfectly.
but the server is returning the following error:
failed to load resource the server responded with a status of 404 (not
found)
for the images stored in laravel_directory/storage/app/public/
i have successfully created symbolic link to public_html/storage by running
ln -sfv /home/dtruxpgw/repositories/SoukElfalah/storage/app/public/
storage
from the public_html directory
i had also tried both
ln -s /home/dtruxpgw/repositories/SoukElfalah/storage/app/public /home/dtruxpgw/public_html/storage
ln -s /home/dtruxpgw/repositories/SoukElfalah/storage/app/public /home/dtruxpgw/public_html
i have run also
php artisan storage:link
and
chmod 775 -R storage
when i run
ls -la /home/dtruxpgw/public_html/storage
i get
lrwxrwxrwx 1 dtruxpgw dtruxpgw 59 Feb 27 09:04
/home/dtruxpgw/public_html/storage ->
/home/dtruxpgw/repositories/SoukElfalah/storage/app/public/
in the cPanel the storage file exist and linked to laravel_directory/storage/app/public/
here it is the html code
<img class="card-img-top thumbnail" src="{{$img_name?asset('/storage/images/thumbs/'.$img_name) : asset('/storage/images/thumbs/default.png')}}" alt="{{$img_name}}">
i have been stacked here for two days now, any help i would really appreciate it
thank you in advance .
You missed one thing is that you can't access the file system from the storage folder directly as you have written above. If you want to access it publicly upload your documents in public directory.
You can only access files from the storage folder through route only.
Move the thumbs folder with the images into public/img and remove the symlink. It makes no sense to do it like this.. Whatever is to be public should be in the public why should you store images into the storage folder?

laravel symlink is changed when code is pushed to live site

I am using laravel 5.5's storage symlink to store images. When I push code to the git and pull from live site then symlink path on live site becomes same as is on my local code .
My local has this symlink
storage -> /home/path/to/project/app/public/
But live site expects this symlink path
storage -> /var/www/html/website.com/public_html/project_code/storage/app/public/
Every time I have to delete symlink and create it again on live site.
I have do these steps on live site
cd public
rm storage
cd ..
php artisan storage:link
after doing these steps my symlink becomes according to live site and then it starts working.
Live site should have this symlink
storage -> /var/www/html/website.com/public_html/project_code/storage/app/public/
project_code/.gitignore :
public/storage
project_code/storage/app/.gitignore
*
!public/
!.gitignore
How I can get rid of this issue.
Thanks in advance!
As your symlink points to another location within the same project, you can safely use relative paths while linking, instead of having absolute one (which is what artisan is setting up). That would require manual linking though:
cd app/public
ln -s ../storage/app/public storage
Remove current storage symlink first if you have it already.
You might consider setting up a post-receive hook in the target Git repo (the one you are pushing to). See this one for instance.
In that hook, you can add any step you need (like fixing the symlink).

Can't see images in localhost

I'm starting to develop a site in ubuntu 14.04. I'm using apache2, so I placed my files under /var/www/html/ folder. Everything was working fine, but I had to restart my current work so I copied the entire project folder from another path, like this
$ sudo cp ~/path/to/folder /var/www/html/
And now I can't see my images, a simple imgtag. I just see this.
When I look for the file, I can see that I'm having an error 403 forbidden. I saw some suggestion to add the option Require all granted but that option is already set in my apache. I suspect that is because the new folder is a copy from a folder without root permissions, so I tried chmod but that also didn't work so I'm completly lost now.
So, how can I see my images from localhost? and most important is why this happen suddenly?

Accessing Symlink folder in ~/Sites folder on Mac (Web Sharing)

I have a local development environment setup on my mac and I am having permission issues accessing a folder in my ~/Sites directory.
Essentially I have Folder A in my Dropbox folder.
I created a SymLink of Folder A to my ~/Sites folder
ln -s ~/Sites ~/Dropbox/FolderA
When I try to access Folder A like so: localhost/~username/FolderA
The page says You don't have permission to access /~username/FolderA on this server
Can someone help me figure out this problem. When I do the same thing on MAMP I don't have this issue. Thanks in advance.
Go on private/etc/apache2/users/, edit your usernamefile.conf, add to the Options line, the option SymLinksIfOwnerMatch, don't use FollowSymLinks if the directory contains important personal files, if for example the dir that you want link is are under your Documents or Dropbox.
Remember that the directory linked by your symbolic link must have 755 permission, and so her parents!
Let's suppose you have /Users/foo/Dropbox/MySites/BarSite, both Users, foo, Dropbox, MySites, BarSite must be 755.

Resources