【问题标题】:Laragon, laravel symbolyc link does not workLaragon,laravel符号链接不起作用
【发布时间】:2018-04-05 22:41:21
【问题描述】:

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

【问题讨论】:

    标签: laravel laravel-5 laravel-5.4 laravel-5.6 laragon


    【解决方案1】:

    如果你在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);
            }
        }
    }
    

    【讨论】:

    • 嗨,谢谢,但它不起作用,我在 Windows 10 上,我的 laragon 在 C:/laragon 我运行 mklink /j [virtual] [source] 命令,它创建文件夹,但文件未同步,因此更改发生时虚拟文件夹未更新:(,在我的 xammp 中一切正常
    猜你喜欢
    • 2018-07-16
    • 2019-09-11
    • 2014-07-06
    • 2016-10-20
    • 1970-01-01
    • 2016-03-10
    • 2017-03-21
    • 1970-01-01
    • 2022-12-21
    相关资源
    最近更新 更多