简体   繁体   English

如何在进行 PHP 工匠存储时更改符号链接文件夹的位置:链接?

[英]How can I change location of symlink folder while doing PHP artisan storage: link?

Got some issues on production.在生产中遇到了一些问题。 In details, I have deployed Laravel project on shared hosting cPanel, I have kept my project in root folder and Laravel`s public folder kept inside public_html, and when I run PHP artisan storage: link it creates a symlink of storage folder in myfolder/public but I want it to go inside public_html具体来说,我已经在共享主机 cPanel 上部署了 Laravel 项目,我将我的项目保存在根文件夹中,并将 Laravel 的公共文件夹保存在 public_html 中,当我运行 PHP artisan storage: link 时,它会在 myfolder/ 中创建一个存储文件夹的符号链接public,但我希望它进入 public_html

How can I do that?我怎样才能做到这一点?

You can create custom symlink via cli !您可以通过 cli 创建自定义符号链接!

cd to your laravel project directory and run the following command cd 到你的 Laravel 项目目录并运行以下命令

ln -sr storage ../public_html/storage 

This will create a symbolic link of your storage folder inside your public_html folder.这将在 public_html 文件夹中创建存储文件夹的符号链接。

A solution could be to make a custom artisan command, something like storage_custom:link and copy the contents of the original storage:link comamnd and just change the paths as you want them to be.一个解决方案可能是创建一个自定义的工匠命令,比如storage_custom:link并复制原始storage:link comamnd 的内容,然后根据需要更改路径。 Here you can see the original storage:link command in Laravel.在这里你可以看到 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.');
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 8.60.0 在我运行 `php artisan storage:link` 时创建一个文件而不是文件夹/符号链接 - Laravel 8.60.0 creates a file instead of a folder/symlink when I run `php artisan storage:link` 在 cpanel 服务器中运行 php artisan storage:link 时出现符号链接问题 - symlink issue when run the php artisan storage:link in cpanel server 如何撤消 php 工匠存储:删除所有存储文件夹内容的链接命令 - How to undo php artisan storage:link command that deleting all storage folder content 输入“ php artisan storage:link”命令后,如何使用Laravel链接存储文件夹在Heroku上显示图像? - How to display images on Heroku using a Laravel linked storage folder, after entering the 'php artisan storage:link' command? 如何更改Laravel Artisan CLI PHP版本? - How can I change the Laravel Artisan CLI PHP version? 如何为 Lumen 的存储公共文件夹创建符号链接 - How to create symlink for storage public folder for Lumen Laravel在使用artisan服务器时未在存储文件夹中显示图像 - Laravel not displaying images in storage folder while using artisan server 在 Dockerfile “php artisan storage:link” 返回非零代码 - In Dockerfile “php artisan storage:link” returns a non-zero code Php 工匠存储:链接删除存储的文件(DigitalOcean) - Php artisan storage:link delete stored files (DigitalOcean) 为什么符号链接在 Laravel 中的 php artisan serve 中不起作用 - Why symlink not working in php artisan serve in laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM