laravel Asset() function break down after deployment - laravel

I developeded a Laravel web app, which works fine and great on local machine but
after going in production on a shared hosting server i have some issues displaying the logo and the website images using the asset() helper function.
However the css and js are accessible and works fine (also using the asset function).
I've deployed the App following the steps bellow:
I created a directory called repositories outside the public_html (the root document of mydomain.com) and i copied inside it directory soukelafalah (contining all the files of my laravel project)
I moved the laravel public directory files into the public_html directory
I edited the index.php in public_html as follow:
require DIR.'./../repositories/SoukElfalah/vendor/autoload.php';
$app = require_once__DIR__.'/../repositories/SoukElfalah/bootstrap/app.php';
I run php artisan storage:link and the link is succufully created
I had run also:
ln -s /home/dtruxpgw/repositories/SoukElfalah/storage/app/public /home/dtruxpgw/public_html/storage
The route and the css is working fine but the logo and the images are not displayed and shows a 404 error as shown in the image below.
So please, can any one point what i am missing?
And when i put asset('/storage/images/thumbs/'.$img_name)}}" am i pointing to the storage directory in the public_html or in the one in the public folder of my laravel app directory.
Thank you in advance.

Related

Image root issue in laravel in cPanel

Images getting stored in outside public folder and in view, getting called from inside public folder. Everything was working fine in local host. After uploading the project in cpanel i took index.php and htaccess outside public folder. How can i store and call them from same folder? Thank you.
When using Laravel all HTTP Requests has to be hit public directory. But since you are using cPanel all Requests hit directly public_html by default.
You tried to overcome it by moving index.php and .htaccess files to public_html from public_html/public and you broke its structure.
If you have the Administrative (eg: root) access on server, you can solve this by editing your Web server (I assume Apache in your case) to point your domain's requests directly to your Laraval application's public directory.
Usually every Web site in cPanel have separate config files. Their paths something like this:
/var/cpanel/userdata/CPANELUSER/WEBSITEDOMAIN.COM and /var/cpanel/userdata/CPANELUSER/WEBSITEDOMAIN.COM_SSL
In this files there is a documentroot field, it points to public_html directory by default:
documentroot: /home/CPANELUSER/public_html
You need to change it and point it to your application's public directory;
documentroot: /home/CPANELUSER/laravel/project/path/public
After you update both of these files, you need to rebuild your Apache config and restart it;
/usr/local/cpanel/scripts/rebuildhttpdconf
/usr/local/cpanel/scripts/restartsrv_httpd
If those 2 lines don't work, you can try this 2;
/scripts/rebuildhttpdconf
/scripts/restartsrv_apache
If everything done well, all HTTP Requests will hit your Laravel application's public directory as expected.
After that; if your uploaded files stores in public storage, Laravel puts them in to storage/app/public and you need a symlink to it from public directory.
Laravel creates it when you run
php artisan storage:link
Now all your application's requests as your.domain/storage/bla.jpg will give a response from storage/app/public/bla.jpg
And if you don't have administrative access to server you can check this tutorial: How to deploy Laravel 8 project on Cpanel shared hosting

Image not showing in blade

I have been working on an open source project recently, currently I am just adding new features in the project.
The project has some images to retrieve and to display them in the view blade that is working perfectly but when I am trying to add a new image through the form, my images are not displaying.
What could be the problem
I have tried
php artisan storage:link
But without success
The issue is when you upload laravel application from one sever to another or from local to live server .It copies shortcut of storage folder too.So before you must delete shortcut folder from public/storage and symbolic link again.
To make these files accessible from the web, you should create a symbolic link from public/storage to storage/app/public.
php artisan storage:link
Ref:https://laravel.com/docs/8.x/filesystem#the-public-disk

Storage laravel. Is this secure to keep private image?

Hi i'm working on sell picture project. I want to secure image in public folder . I follow this way How to protect image from public view in Laravel 5?
Everything work fine. I just want to make sure in storage Path thier is no way to access with URL right? I put my image into storage/images not storage/app/public
If i storage link it will be effect to my private image or not thanks
In Laravel the root of the webserver is the public directory and the entrypoint is public/index.php.
This means that you can access via web server everything under public directory (like javascript/css files and image assets).
The storage directory is one level up and there is no way to access it.
In the discussion you mention the url http://www.somedomainname.net/images/users/userImage.jpg refers to the file userImage.jpg under /your/document/root/laravel/app/public/images/users by default, so the storage directory is not even read.
Laravel, though, will let you link the storage/app/public directory inside the public/storage directory, using the command php artisan storage:link, but that's it.

Can not access php inside laravel assets folder

I have problems with loading some files from laravel assets folder.
I am using laravel 4.2.
This works fine in my local environment but not works on shared hosting. This used to work but somehow stops working.
I have made tester.php and put it into assets folder and I can not access it. Here is a url which returns 404: http://example.com/assets/vendors/kcfinder-2.54/tester.php.
The whole problem starts when I have noticed that I have problem with kcfinder.
This is inside ckeditor config.js:
config.filebrowserImageBrowseUrl = '/assets/vendors/kcfinder-2.54/browse.php?opener=ckeditor&type=images';
config.filebrowserUploadUrl = '/assets/vendors/kcfinder-2.54/upload.php?opener=ckeditor&type=files';
and this not works. Even if I try to acces it directkly using: http://example.com/assets/vendors/kcfinder-2.54/tester.php
I can not open this url. Gives me 404.
But then I have made assets2 folder and all start to work. So I have changed config.js to
config.filebrowserImageBrowseUrl = '/assets2/vendors/kcfinder-2.54/browse.php?opener=ckeditor&type=images';
config.filebrowserUploadUrl = '/assets2/vendors/kcfinder-2.54/upload.php?opener=ckeditor&type=files';
and kcfinder starts to work.Also I can open directly url http://example.com/assets2/vendors/kcfinder-2.54/tester.php
So what is the best way to detect why laravel is not serving php from assets folder?

Laravel 5.2 not loading any assets

None of my assets are loading in my project I've been using a virtual host and it won't load them from the resources/assets/js folder and I've also tried using localhost:8000 does anyone know why?
scripts or any related files that should be accessed via url should be stored in the public directory

Resources