# How to create laravel storage symbolic link for production or sub domain system? (Phần 2)

## [How to create laravel storage symbolic link for production or sub domain system?](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)

[Ask Question](https://stackoverflow.com/questions/ask)Asked 5 years, 4 months agoModified [11 days ago](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system?lastactivity)Viewed 90k times34

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.

* [php](https://stackoverflow.com/questions/tagged/php)
* [laravel](https://stackoverflow.com/questions/tagged/laravel)
* [terminal](https://stackoverflow.com/questions/tagged/terminal)
* [console](https://stackoverflow.com/questions/tagged/console)
* [storage](https://stackoverflow.com/questions/tagged/storage)

[Share](https://stackoverflow.com/q/45825889)Follow[edited Dec 13, 2017 at 18:10](https://stackoverflow.com/posts/45825889/revisions)[![Cœur's user avatar](https://www.gravatar.com/avatar/e8891617e36b8d1254eb3ce1a5662da4?s=64\&d=identicon\&r=PG)](https://stackoverflow.com/users/1033581/c%C5%93ur)[Cœur](https://stackoverflow.com/users/1033581/c%C5%93ur)36.1k2424 gold badges191191 silver badges258258 bronze badgesasked Aug 22, 2017 at 19:49[![Mizanur Rahman Khan's user avatar](https://i.stack.imgur.com/3jQ5Z.jpg?s=64\&g=1)](https://stackoverflow.com/users/7337636/mizanur-rahman-khan)[Mizanur Rahman Khan](https://stackoverflow.com/users/7337636/mizanur-rahman-khan)1,50211 gold badge1111 silver badges1919 bronze badges

* 1If you want to create symbolic link in cpanel read this article [namecheap.com/support/knowledgebase/article.aspx/9561/29/…](https://www.namecheap.com/support/knowledgebase/article.aspx/9561/29/how-to-create-a-symbolic-link-in-cpanel) – [RN Kushwaha](https://stackoverflow.com/users/2995263/rn-kushwaha) [Nov 7, 2018 at 7:09](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment93259205_45825889)&#x20;
* For people looking for the docs: [laravel.com/docs/7.x/filesystem#the-public-disk](https://laravel.com/docs/7.x/filesystem#the-public-disk) – [Ryan](https://stackoverflow.com/users/470749/ryan) [Mar 17, 2020 at 23:43](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment107450994_45825889)

[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)

### 13 Answers

Sorted by:                                              Highest score (default)                                                                   Trending (recent votes count more)                                                                   Date modified (newest first)                                                                   Date created (oldest first)                              72

I solved this problem by another command for creating a symbolic link by terminal/cmd/shh:

```php
ln -s /path/to/laravel/storage/app/public /path/to/public/storage
```

I solved this also Using laravel web route routes/web.php

```php
Route::get('/foo', function () {
    Artisan::call('storage:link');
});
```

[Share](https://stackoverflow.com/a/45825890)Follow[edited Dec 31, 2019 at 9:04](https://stackoverflow.com/posts/45825890/revisions)answered Aug 22, 2017 at 19:49[![Mizanur Rahman Khan's user avatar](https://i.stack.imgur.com/3jQ5Z.jpg?s=64\&g=1)](https://stackoverflow.com/users/7337636/mizanur-rahman-khan)[Mizanur Rahman Khan](https://stackoverflow.com/users/7337636/mizanur-rahman-khan)1,50211 gold badge1111 silver badges1919 bronze badges

* 1in 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 – [Vishnoo Rath](https://stackoverflow.com/users/827225/vishnoo-rath) [Mar 28, 2019 at 10:56](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment97511922_45825890)&#x20;
* how can i run this – [Anoop P S](https://stackoverflow.com/users/1338683/anoop-p-s) [May 15, 2019 at 10:45](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment98924388_45825890)
* how can we run terminal in cpanel ? – [Haritsinh Gohil](https://stackoverflow.com/users/7719176/haritsinh-gohil) [Jul 22, 2019 at 7:26](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment100797313_45825890)
* 1Delete public/storage folder and run php artisan storage:link again. It worked for me. – [Alaksandar Jesus Gene](https://stackoverflow.com/users/2491541/alaksandar-jesus-gene) [Aug 2, 2019 at 4:25](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment101130597_45825890)
* @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](https://stackoverflow.com/users/10329023/kamlesh) [Aug 6, 2019 at 7:10](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment101226514_45825890)&#x20;

[Show 6 more comments](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)39

Another simple way is to run Executing `php artisan storage:link` Command Programmatically

On routes/web.php

```php
Route::get('/foo', function () {
Artisan::call('storage:link');
});
```

[Share](https://stackoverflow.com/a/55418359)Follow[edited Apr 25, 2019 at 7:09](https://stackoverflow.com/posts/55418359/revisions)[![Amir's user avatar](https://i.stack.imgur.com/X5Do3.jpg?s=64\&g=1)](https://stackoverflow.com/users/2503722/amir)[Amir](https://stackoverflow.com/users/2503722/amir)8,72177 gold badges4444 silver badges4848 bronze badgesanswered Mar 29, 2019 at 13:21[![Fhulufhelo Mokhomi's user avatar](https://lh4.googleusercontent.com/-BoiEXcdF26M/AAAAAAAAAAI/AAAAAAAAAEU/coyrz0zaPJ0/photo.jpg?sz=64)](https://stackoverflow.com/users/5820693/fhulufhelo-mokhomi)[Fhulufhelo Mokhomi](https://stackoverflow.com/users/5820693/fhulufhelo-mokhomi)55955 silver badges66 bronze badges

* 6This command works fine in local but gives error in live symblink error – [Anoop P S](https://stackoverflow.com/users/1338683/anoop-p-s) [May 15, 2019 at 10:45](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment98924382_55418359)
* 1YOU ARE MY HERO, Saved My Life, Thank You :) – [Kamlesh](https://stackoverflow.com/users/10329023/kamlesh) [Aug 6, 2019 at 7:12](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment101226583_55418359)
* 1Life saver thank you bro works great but i had to delete the storage file existe in the public folder, then create anew symlink, thanks – [Ridha Rezzag](https://stackoverflow.com/users/6561930/ridha-rezzag) [Apr 28, 2020 at 2:33](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment108740793_55418359)
* 9`symlink(): No such file or directory` – [Saeed](https://stackoverflow.com/users/9422637/saeed) [Aug 13, 2020 at 4:10](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment112086077_55418359)
* symlink() has been disabled for security reasons – [Mohsin AR](https://stackoverflow.com/users/2055782/mohsin-ar) [May 22, 2021 at 20:59](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment119581616_55418359)

[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)6

In case anyone is looking for another flexible solution using php:

```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.

[Share](https://stackoverflow.com/a/65870348)Followanswered Jan 24, 2021 at 12:08[![Ali Ali's user avatar](https://www.gravatar.com/avatar/ee5bb9e9a8763cdf333babcffaa76301?s=64\&d=identicon\&r=PG)](https://stackoverflow.com/users/10470283/ali-ali)[Ali Ali](https://stackoverflow.com/users/10470283/ali-ali)1,65522 gold badges1717 silver badges3232 bronze badges

* very nice solution :) – [mahdi marjani moghadam](https://stackoverflow.com/users/1554168/mahdi-marjani-moghadam) [Sep 23, 2021 at 14:24](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment122488610_65870348)

[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)5

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.

```php
$ mv storage /home/yourHostinInfo/domains/domainName/public_html
```

the path might be different based on your hosting information.

[Share](https://stackoverflow.com/a/61359130)Followanswered Apr 22, 2020 at 7:04[![AL-IMRAN's user avatar](https://i.stack.imgur.com/bqn6v.jpg?s=64\&g=1)](https://stackoverflow.com/users/8669836/al-imran)[AL-IMRAN](https://stackoverflow.com/users/8669836/al-imran)5111 silver badge22 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)3

**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.

```php
ln -s target_path link_path
```

Example (in CPanel File Directory)

```php
ln -s /home/cpanel_username/project_name/storage/app/public /home/cpanel_sername/project_name/public/storage
```

[Share](https://stackoverflow.com/a/62283265)Followanswered Jun 9, 2020 at 13:02[![Mateus Gonçalves's user avatar](https://graph.facebook.com/2085280788451479/picture?type=large)](https://stackoverflow.com/users/10842583/mateus-gon%C3%A7alves)[Mateus Gonçalves](https://stackoverflow.com/users/10842583/mateus-gon%C3%A7alves)66655 silver badges1515 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)2

If you are using a CPANEL web hosting its common for the domain root to be `public_html` directory which may be an issue as by default Laravel app will try to look for a folder called `public` in your project root. To solve this open your `config/filesystems.php` file and change:

```php
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/

'links' => [
    public_path('storage') => storage_path('app/public'),
],
```

to this:

```php
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/

'links' => [
    base_path('public_html/storage') => storage_path('app/public'),
],
```

Note that we have changed the `links` array value from the default `public_path('storage')` to our custom `base_path('public_html/storage')` directory

[Share](https://stackoverflow.com/a/67013206)Follow[edited Apr 9, 2021 at 13:50](https://stackoverflow.com/posts/67013206/revisions)answered Apr 8, 2021 at 23:41[![Software Developer's user avatar](https://graph.facebook.com/1924191637887501/picture?type=large)](https://stackoverflow.com/users/10708470/software-developer)[Software Developer](https://stackoverflow.com/users/10708470/software-developer)71088 silver badges1111 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)1

I have an account on Hostinger.

I had a big problem with Laravel File Manager, but now I know what was the problem :)

It\`s was an issue with a link to storage. My folder public\_html had no link but the copy of storage!

1. Delete this storage or rename it if you want backup :)
2. Log in to ssh and use command pwd to get the current folder that will help you build a full path.
3. Use this command:

   ln -s \<target\_path> \<link\_path>

In my case this was like:

```php
ln -s /home/u16345434/domains/website.name/storage/app/public /home/u16345434/domains/website.name/public_html/storage
```

Good Luck :)

[Share](https://stackoverflow.com/a/70762676)Followanswered Jan 18 at 21:38[![Adam Boniecki's user avatar](https://www.gravatar.com/avatar/29f083ca0a6f853c88ff82191c52def9?s=64\&d=identicon\&r=PG\&f=1)](https://stackoverflow.com/users/15203491/adam-boniecki)[Adam Boniecki](https://stackoverflow.com/users/15203491/adam-boniecki)5122 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)1

The easiest option is to run the following in a terminal

```php
php artisan storage:link
```

[Share](https://stackoverflow.com/a/71904658)Followanswered Apr 17 at 18:58[![Wakil Ahmed's user avatar](https://lh3.googleusercontent.com/-8gRyA2oXC5s/AAAAAAAAAAI/AAAAAAAAAAA/AMZuucm2ALmH1oPJOiA_CpTojcT1AC9Ctg/s96-c/photo.jpg?sz=64)](https://stackoverflow.com/users/15338342/wakil-ahmed)[Wakil Ahmed](https://stackoverflow.com/users/15338342/wakil-ahmed)29833 silver badges1212 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)0

I had an issue creating a symlink to a folder located under `subdomain`, tried everything for almost 3 hours, and no luck. My case was as follow:

1. The uploads folder is located under subdomain: `images.example.com`.
2. I upload images using the root document: `$_SERVER['DOCUMENT_ROOT'].'/uploads/`
3. I want to create a symlink in that root document.

**Finally, I tried this solution and it works as expected:**

`ln -s /home/customer/www/images.example.com/public_html/uploads /home/customer/www/example.com/public_html/uploads`

*Note: I used `PuTTY` to create that symlink*

[Share](https://stackoverflow.com/a/62578356)Followanswered Jun 25, 2020 at 14:59[![Jodyshop's user avatar](https://i.stack.imgur.com/5PieL.jpg?s=64\&g=1)](https://stackoverflow.com/users/8585501/jodyshop)[Jodyshop](https://stackoverflow.com/users/8585501/jodyshop)63688 silver badges1212 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)0

Just write in a php file (like symlink.php) the following code, place it in the website root folder (the folder you placed files in the public folder) and execute it by browsing in your browser to yourwebsite/symlink.php

```php
<?php
symlink('/home/yourrootfolder/yourappfolder/storage/app/public', '/home/yourrootfolder/public_html/yourappfolder/storage');
```

[Share](https://stackoverflow.com/a/73377856)Followanswered Aug 16 at 17:17[![Ayenew Yihune's user avatar](https://i.stack.imgur.com/DS5uZ.jpg?s=64\&g=1)](https://stackoverflow.com/users/9539538/ayenew-yihune)[Ayenew Yihune](https://stackoverflow.com/users/9539538/ayenew-yihune)8411010 silver badges1616 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)0

Here is the code that works for me in the production server

```php
 Route::get('/linkstorage', function () {
    $targetFolder = base_path().'/storage/app/public';
    $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage';
    symlink($targetFolder, $linkFolder);
 });
```

[Share](https://stackoverflow.com/a/74071107)Followanswered Oct 14 at 14:55[![Joynal Abedin's user avatar](https://graph.facebook.com/896085430506979/picture?type=large)](https://stackoverflow.com/users/5925849/joynal-abedin)[Joynal Abedin](https://stackoverflow.com/users/5925849/joynal-abedin)6777 bronze badges[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)0

to solve the problem instead of `ln -s path/to/target path/to/public/storage` just type:

`ln -srv ~/path/to/target ~/path/to/public/storage`

but first create the folder storage in public.

[Share](https://stackoverflow.com/a/74207248)Follow[edited Dec 18 at 7:11](https://stackoverflow.com/posts/74207248/revisions)[![justANewb stands with Ukraine's user avatar](https://i.stack.imgur.com/U14ou.jpg?s=64\&g=1)](https://stackoverflow.com/users/14193797/justanewb-stands-with-ukraine)[justANewb stands with Ukraine](https://stackoverflow.com/users/14193797/justanewb-stands-with-ukraine)3,48533 gold badges1111 silver badges3333 bronze badgesanswered Oct 26 at 11:47[![Brro Jindy's user avatar](https://lh5.googleusercontent.com/-x5lEaiG_HxI/AAAAAAAAAAI/AAAAAAAAAAA/AMZuuclyPmij7sg_OwLavZyvM7ktIeFGCA/s96-c/photo.jpg?sz=64)](https://stackoverflow.com/users/14639796/brro-jindy)[Brro Jindy](https://stackoverflow.com/users/14639796/brro-jindy)111 bronze badge

* Your answer could be improved with additional supporting information. Please [edit](https://stackoverflow.com/posts/74207248/edit) to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](https://stackoverflow.com/help/how-to-answer). – [Prateek Varshney](https://stackoverflow.com/users/8602779/prateek-varshney) [Oct 30 at 5:14](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system#comment131090131_74207248)

[Add a comment](https://stackoverflow.com/questions/45825889/how-to-create-laravel-storage-symbolic-link-for-production-or-sub-domain-system)-2

All you have to do is access the server through SSH, navigate to the root path where it is your laravel project, for example:

```php
cd /path/to/your/domain/public_html
```

then navigate to the `public` directory(laravel project) and delete the `storage` directory if you have uploaded it...

and go back to the `public_html` and run the command:

```php
php artisan storage:link
```

that will get the job done...

[Share](https://stackoverflow.com/a/67114720)Follow
