skip to Main Content

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

How can I do that?

2

Answers


  1. 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. Here you can see the original storage:link command in Laravel.

    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.');
        }
    }
    
    
    Login or Signup to reply.
  2. You can create custom symlink via cli !

    cd to your laravel project directory and run the following command

    ln -sr storage ../public_html/storage 
    
    

    This will create a symbolic link of your storage folder inside your public_html folder.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search