【问题标题】:How can I change location of symlink folder while doing PHP artisan storage: link?如何在进行 PHP 工匠存储时更改符号链接文件夹的位置:链接?
【发布时间】:2020-04-03 09:33:52
【问题描述】:

在生产中遇到了一些问题。 具体来说,我已经在共享主机 cPanel 上部署了 Laravel 项目,我将我的项目保存在根文件夹中,并将 Laravel 的公用文件夹保存在 public_html 中,当我运行 PHP artisan storage: link 它在 myfolder/ 中创建一个存储文件夹的符号链接public,但我希望它进入 public_html

我该怎么做?

【问题讨论】:

  • "我将我的项目保存在根文件夹中,而 Laravel 的公共文件夹保存在 public_html 中" 你实际上做了什么?你只是将你的 laravel 应用程序的公共目录复制到你的 public_html 中吗?或在您的 laravel/public 和 public_html 之间创建符号链接
  • 将公用文件夹内容复制到public_html中
  • 这行得通吗?我的意思是你可以通过点击 url 来运行你的应用程序吗?
  • 是的,它正在工作

标签: php laravel laravel-5


【解决方案1】:

一种解决方案可能是制作自定义工匠命令,例如 storage_custom:link 并复制原始 storage:link comamnd 的内容,然后根据需要更改路径。在这里你可以看到 Laravel 中原始的storage:link 命令。

class StorageLinkCommand extends Command
{
    /**
     * The console command signature.
     *
     * @var string
     */
    protected $signature = 'storage:link';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a symbolic link from "public/storage" to "storage/app/public"';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        if (file_exists(public_path('storage'))) {
            return $this->error('The "public/storage" directory already exists.');
        }

        $this->laravel->make('files')->link(
            storage_path('app/public'), public_path('storage')
        );

        $this->info('The [public/storage] directory has been linked.');
    }
}

【讨论】:

  • 谢谢你,我试过了,这会返回 symlink(): No such file or directory 错误
  • 尝试删除使用 storage:link 创建的原始符号链接。您还可以告诉我您是如何根据需要编辑 artisan storage 命令的吗?并且您的目录结构的屏幕截图可能会很有用。谢谢。
【解决方案2】:

您可以通过 cli 创建自定义符号链接!

cd 到你的 laravel 项目目录并运行以下命令

ln -sr storage ../public_html/storage 

这将在您的 public_html 文件夹中创建一个存储文件夹的符号链接。

【讨论】:

    猜你喜欢
    • 2017-12-10
    • 2012-12-14
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2019-01-11
    • 2019-06-20
    相关资源
    最近更新 更多