How to create laravel storage symbolic link for production or sub domain system?

前端 未结 6 646
天涯浪人
天涯浪人 2021-02-04 02:41

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

相关标签:
6条回答
  • 2021-02-04 03:03

    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');
    });
    
    0 讨论(0)
  • 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');
    });
    
    0 讨论(0)
  • 2021-02-04 03:23

    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.

    0 讨论(0)
  • 2021-02-04 03:24

    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

    0 讨论(0)
  • 2021-02-04 03:26

    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
    
    0 讨论(0)
  • 2021-02-04 03:29

    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.

    0 讨论(0)
提交回复
热议问题