在执行PHP artisan storage:link时,如何更改symlink文件夹的位置?

时间:2019-12-10 08:37:50

标签: php laravel laravel-5

在生产中遇到了一些问题。 详细地说,我已经在共享托管cPanel上部署了Laravel项目,将项目保留在根文件夹中,而Laravel的公共文件夹则保留在public_html中,并且当我运行PHP artisan storage时:链接会在myfolder /中创建存储文件夹的符号链接公共,但我希望它进入public_html

我该怎么做?

2 个答案:

答案 0 :(得分:1)

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

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

ln -sr storage ../public_html/storage 

这将在public_html文件夹内创建存储文件夹的符号链接。

答案 1 :(得分:0)

一个解决方案可能是制作一个自定义的工匠命令,类似storage_custom:link,并复制原始storage:link comcomnd的内容,然后根据需要更改路径。在这里,您可以看到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.');
    }
}