The page accessed using the symbolic / soft link doesn't change its content as it was cached (cache cleared) - symlink

Whenever I try to access the path https://example.com/example/symlink, the page remains the same as it was before.
The symbolic link points to the Laravel Public directory https://example.com/example/laravel/laravel/public but that's not a question about the Laravel framework.
I changed the background color in the .css file and when I try to access a website using the https://example.com/example/symlink the CSS rules don't apply while using the https://example.com/example/laravel/laravel/public works perfectly.
It couldn't be an issue with the Laravel framework, it has to do with the symbolic links.

Related

Change document root of Laravel

When I place a Laravel project into Apache's document root, say /var/www/html, it works when I point a browser at it.
However if I put it under a directory under Apache's document root, for example /var/www/html/myProject, it doesn't work when I point a browser at it.
Is there anyway I can change this behavior?
Thank you very much.
Edit:
When I put the Laravel project off a sub-directory off /var/www/html, Laravel complained that it could not write to the file laravel.log. After checking and changing the group ownership of the sub-directory, the index page came up normally.
However, the background image was missing, even after I changed the URI in the CSS stylesheet.
Furthermore, when I clicked on any link from the index page, I got a 404 Not Found Error. This is an Apache 404 and not a Laravel 404, which is styled differently.
OTOH, if I run the PHP server off this sub-directory and point my browser at localhost:8000, the links serve up pages correctly.
Thank you for your help.

Symbolic link from public/storage to storage/app/public still makes the files in the storage directory accessible from the web

What I have done
When I researched about storing files in laravel. I came across two approaches.
Storing the assets directly inside the public folder.
Creating a symbolic link from public/storage to
storage/app/public
When I researched about which one two use, I came across this stack overflow link. 👉 Difference between storing files in public directory and in storage in Laravel 5.4
In this link in the top answer it was mentioned,
Public folder means files will be publicly accessible.
For example an image stored in
public/images/my-image.jpegcan be viewed by anyone by
going to mysite.com/images/my-image.jpeg
However, files stored in storage directory are only available to your
app.
👆 Since, including in the mentioned stack overflow post above, and many other posts I have read on different platforms implied the fact that files in the public directory are web accessible whereas the files inside the storage directory are not, I tried to test this by storing files both in the public directory and in the storage directory one at a time, and then checking if the files are accessible through the web url.
My attempts went as below,
First I added the path images/ in the public
directory and placed some images (Let us say
test1.jpg, test2.jpg and
test3.jpg) into that directory. Then inside my blade
template for the src attribute of my
img tags I referred to them as
URL('images/test1.jpg') etc... and they were indeed
rendered on the webpage. Then I also tried to access the images from
the url by going to
http://localhost:8000/images/test.jpg. The result was
as expected, The images were rendered on the web page + they were
accessible from the url
Then I ran the command php artisan storage:link
on the console, which according to the articles I read, should
create a symbolic link between the directories
public/storage and storage/app/public.
As soon as I ran the command, I got a new folder called
storage created in the public
directory. Then I moved all my images to that
public/storage directory. Then set the
src attribute my img tags as
URL('storage/test1.img') etc... the images were
rendered on the web page. Then I tried to check if the images are
still accessible from the url. for that on the url bar I went to
http://localhost:8000/storage/test1.jpg. The
images were STILL ACCESSIBLE from the url.
Problem
However, according to the answer I have mentioned and some other similar links, I expected those images to not be accessible from the url in the 2) above since the images should now be actually in the storage/app/public which we have created a symbolic link to from public/storage. (Files inside the storage directory should not be publicly accessible right?)
This led me to two questions,
Why are the images are still being accessible from the url even after I created a symbolic link from public/storage to storage/app/public and stored the images in the public/storage directory?
As happened with my case, if the files in the
public/storage are still accessible through the web
url, what are the advantages of actually creating the symbolic link?
It does not seem to offer any more security since the files are
still accessible from the url.
It would be really helpful if anyone can help me understand the answers to the above two questions I have. Thanks.
What's happening to you is the expected behavior.
The purpose of Laravel storage is to interact with your local files and make use of Laravel helpers, besides being easily shared across deployments.
Saying that I would avoid moving your files directly to your public folder.
On the other hand, by adding files to your storage/app/public folder you are assuming that those files will be publicly accessible, but they won't be until you create a symbolic link which is a special kind of file that points to another file.
When you create a symbolic link you are saying "hey, if the user reaches http://localhost:8000/storage/ just show the files stored in storage/app/public"
So if you want private files (and you have created a symbolic link) just don't upload them to your storage/app/public folder, instead of that put your private files out from the public folder such as storage/app/myfiles
He are your answers:
1 - Why are the images are still being accessible from the url even
after I created a symbolic link from public/storage to
storage/app/public and stored the images in the public/storage
directory?
Because in fact, you have created a symbolic link for that purpose, making the storage/app/public publicly accessible.
2 - As happened with my case, if the files in the public/storage are
still accessible through the web url, what are the advantages of
actually creating the symbolic link? It does not seem to offer any
more security since the files are still accessible from the url.
As said, the advantage is to make use of Laravel filesystem. The public link doesn't determine the privacy of your files
You might have many different types of files in one project. Some are accessible to the public, like images embedded in a website (as your example shows), and some are private files, let's say, for example, a pdf of a private report.
Any file that is accessible to the public can be stored in either storage/public or directly in public. As you have observed, no difference there since the former would have a symlink established.
However, private files cannot be stored storage/public (if symlink is established) and especially not directly in public folder for obvious reasons.
Those files can go in storage/app/NOT_PUBLIC_REPO. These files should be made accessible via protected routes (along with signed routes if you want extra protection).

Laravel Vapor - Assets (logo) on maintenance mode page

According to the docs we are able to put a 503.html document inside the root of our Laravel project.
You may customize the maintenance mode splash screen for your application by placing a 503.html file in your application's root directory.
I would however love to be able to put one or more assets on this page (for example our Logo) to make this page better more personal. Laravel Vapor automatically uploads your static assets to cloudfront, which is not a problem if you're using the asset() helper. However, are there any solutions already being made? I can't find any.
Is there anyone who has created a solution to make this happen?
With Vapor every time you deploy all the assets get a new cloudfront url. This is mostly fine for js and css which we change often. Images, logos etc do not change much.
Better to make another bucket on aws and hard code the path the image file in your 503. Doesn't need to be deployed every time. Your users browsers can cache it for as long as you set it in the bucket.
I'd like Vapor to only change asset urls if the files have changed but so far that is not the case.

Locating the main website (front page) file in cpanel for website built on laravel and voyager

I am trying to locate the file or folder in cpanel that the front page of my website is housed in so i can add a floating action button script to my website.
I just have no prior experience here.
(I am trying to add this in correct place)
It should have a finished result as here http://www.floatingactionbutton.com
The views or 'pages' of the application should be in the resources/views/ directory. You may find a view that is 'home' or something similar but there is no way of knowing what the views have been named when your application was developed.
The views may not be in straight HTML / PHP but rather use Laravel's Blade syntax.
In addition, existing javascript files in your site may have been compiled using Webpack. I imagine the floating action button will be a javascript script.
Can you get the original developer to add the script for you?

Laravel Create Download Link To Storage

I have a file in /storage/excel/exports/abc.xls and I want to create a download link to it, so I wrote:
<a href="{{asset('storage/excel/exports/'.$file)}}" download>{{$file}}</a>
But when I click on the link, it cannot find the file. then I looked at href in Inspect Element and the link was http://localhost/[my-project]/public/storage/excel/exports/abc.xls
And when I cleaned public/ using Inspect Element and changed href value, the link worked fine and it downloaded the file.
I have different ways to solve this issue but i'm sure none of them is best practice.
Whats the best way to create a link to a file in storage folder in laravel?
If you're on Laravel 5.5 you can use the Storage class. You can then use Storage::url($file) and it should get the proper URL for your file.
However, as per the docs:
Remember, if you are using the local driver, all files that should be publicly accessible should be placed in the storage/app/public directory. Furthermore, you should create a symbolic link at public/storage which points to the storage/app/public directory.

Resources