Laragon,laravel 符号链接不起作用

米凯尔 G。

我使用的是laragon laravel,一切正常exept,当我上传图片,他们返回404,并public/storage为空但storage/app/public有文件,也public/public有文件,所以它创建公用文件夹内的错误的文件夹公开,我也跑了php artisan storage:link command作为我说它创建了存储链接,我可以在我的编辑器中看到它,但是文件转到public/public而不是public/storage,我怎样才能让它工作?我想这是 laragon 的问题,因为它可以在其他环境中工作,我也使用“命名”url 运行我的网站:myproject.test,我使用 apache2 作为 Web 服务器,请帮助修复它

塔哈厚

如果你在linux上,你可以使用

ln -s [source] [virtual] 

创建虚拟链接。在 Windows 上,您可以使用

mklink /j [virtual] [source]

做同样的事情。

请注意,您可能需要使用完整路径来创建链接。我在 laragon 上使用这种方法并且它有效。如果它们转到所需的文件夹,请在创建符号链接后双击链接来检查它是否有效。如果没有,则配置有问题。


奖金

我创建了一个控制台命令来自动化操作,也许您可​​以使用它:

用法: php artisan install:symlink

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class installSymlink extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'install:symlink';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'This artisan command installs pinpacker symlinks';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //

        $links = ["./public/thumbnails","./public/resized"];
        $folders = ["./storage/app/public/thumbnails/","./storage/app/public/resized/"];

        chdir(base_path());

        try {
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                foreach($links as $i => $link){
                    $command = 'mklink /j "' . str_replace('/', '\\', $link) . '" "' . str_replace('/', '\\', $folders[$i]) . '"';
                    echo $command."\n";
                    exec($command);
                }
            } else {
                foreach($links as $i => $link){
                    $command = 'ln -s ' . realpath($folders[$i]) . ' ' . $link;
                    echo $command ."\n";
                    exec($command);
                }
            }
            printf("Symlinks created.\n");
        } catch (Exception $e) {
            printf($e->getMessage());
            print_r($e);
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章