How to create laravel storage symbolic link for production or sub domain system?
Solution 1
I solved this problem by another command for creating a symbolic link by terminal/cmd/shh:
ln -s /path/to/laravel/storage/app/public /path/to/public/storage
I solved this also Using laravel web route routes/web.php
Route::get('/foo', function () {
Artisan::call('storage:link');
});
Solution 2
Another simple way is to run Executing php artisan storage:link
Command Programmatically
On routes/web.php
Route::get('/foo', function () {
Artisan::call('storage:link');
});
Solution 3
assuming that your laravel project "public" directory and "public_html" directory are different. Or your subdomain pointer directory may be different , then use your subdomain pointer directory like "public_html" below given process.
apply command: $ php artisan storage:link
this command will create symlink to "public" directory to your laravel project. not inside the "public_html" . so we need to move the "storage" link to "public_html" directory. for this you can move directly. if it doesn't work then move it using command . go inside the "public" directory and run the below command according to your "public_html" directory location.
$ mv storage /home/yourHostinInfo/domains/domainName/public_html
the path might be different based on your hosting information.
Solution 4
In case anyone is looking for another flexible solution using php:
Route::get('/link', function () {
$target = '/home/public_html/storage/app/public';
$shortcut = '/home/public_html/public/storage';
symlink($target, $shortcut);
});
And make any required change to the $target variable and the $shortcut upon your files structure.
You can use the above code inside that web route or inside any other function.
Solution 5
Creating symbolic link in a web server using SSH
In Laravel documentation, a symbolic link (symlink or soft link) from public/storage to storage/app/public should be created to make files accessible from the web.
(THIS PROCEDURE WILL CREATE SYMBOLIC LINK WITHIN THE LARAVEL PROJECT DIRECTORY)
Here are the steps on how you can create symbolic link in your Linux web server using SSH client:
1. Connect and login to your web server using SSH client (e.g. PUTTY).
2. Link storage/app/public to public/storage using the syntax.
ln -s target_path link_path
Example (in CPanel File Directory)
ln -s /home/cpanel_username/project_name/storage/app/public /home/cpanel_sername/project_name/public/storage
Related videos on Youtube
Mizanur Rahman Khan
I have 7 years' experience in the area “Software design and Development”. Now I am working at “Yakoun Inc. Ltd” in the post of “Full Stack Developer” Remote Job, Location (107 Valley Oaks Loop, Union City CA, USA) from July 2019 to Continue. My work responsibilities are Yakoun Ecommerce Software (iOS and Android) and web app development Technology: Laravel (PHP), React JS, MySQl, Redis Web: https://yakoun.com/ iOS: https://apps.apple.com/US/app/id1512738197 Android: https://play.google.com/store/apps/details?id=com.yakoun.yakoun Flex Music Software (iOS and Android) and web app development Technology: Laravel (PHP), React JS, MySQl, Redis, Video Editor using ffMPeg-php, ffmpeg-mobile, android-ffmpeg, ios-ffmpeg Web: https://flexmusix.com/ iOS: https://apps.apple.com/us/app/flex-musix/id1574289158 Android: https://play.google.com/store/apps/details?id=com.flexmusix Flex Videos Software (iOS and Android) and web app development Technology: Laravel (PHP), React JS, MySQl, Redis, Video Editor using ffMPeg-php, ffmpeg-mobile, android-ffmpeg, ios-ffmpeg
Updated on July 12, 2022Comments
-
Mizanur Rahman Khan almost 2 years
When I worked on laravel local development server
php artisan storage:link
works fine for me. But when I transfer my site to production server then I saw my public storage link was a folder. Then I delete that tried to create a link. I got an error because my app was in the root folder and tried to solve this problem.-
RN Kushwaha over 5 yearsIf you want to create symbolic link in cpanel read this article namecheap.com/support/knowledgebase/article.aspx/9561/29/…
-
Ryan about 4 yearsFor people looking for the docs: laravel.com/docs/7.x/filesystem#the-public-disk
-
-
Vishnoo Rath about 5 yearsin my case I had to runt this command with the full path i.e $HOME/domain.com/storage/app/public $HOME/public_html/storage . Hostgator shared hosting
-
Anoop P S almost 5 yearsThis command works fine in local but gives error in live symblink error
-
Anoop P S almost 5 yearshow can i run this
-
Haritsinh Gohil almost 5 yearshow can we run terminal in cpanel ?
-
Alaksandar Jesus Gene almost 5 yearsDelete public/storage folder and run php artisan storage:link again. It worked for me.
-
Kamlesh over 4 years@MizanurRahmanKhan it is showing an error in command terminal. 'ln' is not recognized as an internal or external command, operable program or batch file.
-
Kamlesh over 4 yearsYOU ARE MY HERO, Saved My Life, Thank You :)
-
Kamlesh over 4 yearsIt works on server only when i set it in cron job to run once.
-
Kamlesh over 4 yearsRoute::get('/foo', function () { Artisan::call('storage:link'); }); It is a perfect solution.
-
Mizanur Rahman Khan over 4 yearsIf you don't have server terminal access then you may use Route::get('/foo', function () { Artisan::call('storage:link'); });
-
Rajan Rawal about 4 yearsBefore executing your command, dont forget to check the user. The owner of the project folder and the user by which you create symlink should match. Also check for the needful folder permission. This two helped to get this working.
-
Ridha Rezzag about 4 yearsLife saver thank you bro works great but i had to delete the storage file existe in the public folder, then create anew symlink, thanks
-
Saeed over 3 years
symlink(): No such file or directory
-
Sagor Islam over 3 yearsjust apply this 2nd method in web.php(route) and see the result. work perfectly.
-
Mohsin AR almost 3 yearssymlink() has been disabled for security reasons
-
Mohsin AR almost 3 yearssymlink() has been disabled for security reasons
-
mahdi marjani moghadam over 2 yearsvery nice solution :)