0
0
Laravelframework~10 mins

Public disk and symbolic links in Laravel - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Public disk and symbolic links
Create storage/app/public folder
Run: php artisan storage:link
Creates symbolic link: public/storage -> storage/app/public
Access files via URL: /storage/filename
Browser serves files from linked folder
This flow shows how Laravel creates a symbolic link from the public folder to storage/app/public, enabling public access to storage files.
Execution Sample
Laravel
php artisan storage:link
// Creates symbolic link
// public/storage -> storage/app/public
// Allows public access to storage files
This command creates a symbolic link so files in storage/app/public are accessible via the public/storage URL.
Execution Table
StepActionResultEffect
1Ensure storage/app/public exists (create manually if needed)Folder existsFolder ready for public files
2Run 'php artisan storage:link'Creates symbolic linkpublic/storage points to storage/app/public
3Verify symbolic linkLink existsFiles in storage/app/public accessible via /storage
4Access file via URL /storage/example.jpgFile served from storage/app/public/example.jpgPublic can view/download file
5Delete symbolic linkLink removedFiles no longer accessible via /storage
💡 Process ends after symbolic link is created and verified for public access
Variable Tracker
VariableStartAfter Step 2After Step 3Final
storage/app/public folderMay not existMay not existExistsExists
public/storage linkDoes not existCreatedExistsExists
File access via /storageFailsFailsSucceedsSucceeds
Key Moments - 3 Insights
Why do we need to run 'php artisan storage:link'?
Because Laravel does not create the symbolic link automatically. Running this command creates the link so files in storage/app/public can be accessed publicly via the web.
What happens if the symbolic link is missing?
Accessing files via /storage URL will fail because the public/storage folder does not point to storage/app/public. See execution_table step 5.
Can we store files outside storage/app/public and access them publicly?
No, only files inside storage/app/public are linked to public/storage. Files outside this folder are not accessible via the symbolic link.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of 'public/storage' link after step 2?
AIt does not exist yet
BIt is deleted
CIt is created and points to storage/app/public
DIt points to a wrong folder
💡 Hint
Check the 'Result' column in execution_table row for step 2
At which step does accessing files via /storage URL become successful?
AStep 3
BStep 1
CStep 5
DNever
💡 Hint
Look at the 'Effect' column in execution_table rows for steps 2 and 3
If the storage/app/public folder does not exist before running the command, what happens?
AThe command fails immediately
BThe link points to a non-existing folder
CThe folder is created and then the link is made
DThe link is created but files are inaccessible
💡 Hint
The storage:link command creates the link but does not create the target folder. See step 1.
Concept Snapshot
Laravel stores public files in storage/app/public.
Run 'php artisan storage:link' to create a symbolic link.
This link is public/storage pointing to storage/app/public.
Files inside storage/app/public become accessible via /storage URL.
Without the link, public access fails.
Keep storage/app/public for public files only.
Full Transcript
In Laravel, files meant for public access are stored in the storage/app/public folder. However, this folder is not directly accessible from the web. To make these files accessible, Laravel uses a symbolic link. Running the command 'php artisan storage:link' creates a symbolic link named public/storage that points to storage/app/public. This means when a user accesses a URL starting with /storage, the server serves files from storage/app/public. The process involves ensuring the storage/app/public folder exists (creating it manually if necessary), running the command to create the link, verifying the link exists, and then accessing files through the public URL. If the symbolic link is missing or deleted, public access to these files will fail. This setup keeps public files organized and accessible securely.