How to create a symbolic link for laravel website in CPanel, that is Laravel Storage Symlink.
There is a simple way to do so, by creating a file and running it. Just follow these steps.
- Make sure you do not have a storage folder created in the public folder. (public_html/public/storage). If so then remove it.
- Create a PHP file name symlink.php in the root folder, which is in the public_html folder.
- And now paste this code.
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public'; $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage'; symlink($targetFolder,$linkFolder); echo 'Symlink process successfully completed';
Now open the file you have just created. The URL would be something like this website.com/symlink.php and this is done. Now you can see the public folder has a storage folder created.
How do we do it in CMD?
Using the artisan command, it is very simple to create a symlink.
Open CMD and go to the directory where your Laravel project is installed.
Now simply add this: php artisan storage:link and hit the enter key.
c:\>xampp\htdocs\LaravelProject\php artisan storage:link
This will create a storage folder in the public folder. Now your files are accessible using