Search code examples
phplaravelshared-hosting

Laravel deployed to shared hosting not saving images


I have deployed Laravel app on a shared hosting. Laravel main folder is outside of "public html", and called "laravel-app". Public folder of Laravel was placed in the "public_html" folder, and ".htaccess" was properly configured. Everything is working perfectly, but I cannot save images.

I use Laravel Backpack 5, and it saves to the database the path to an image correctly. If I manually place an image in that folder, and give the same name then it shows on website. However, it does not get saved from admin panel. Everything is working in my Localhost.


Solution

  • Laravel uploads files (images, ... ) as default in the storage folder, and when you change your project files directories manually (put main folder outside of "public_html", and called "laravel-app"), Laravel doesn't access to the default directory for saving files.

    You must open the config folder in your root directory of the project (here in your laravel-app folder) and open filesystems.php

    In this file, you must check your default FILESYSTEM_DISK. For example, it is local as the default

    So scroll to this part

    'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
            'throw' => false,
        ],
    

    and change root to an absolute address for root like:

    'local' => [
            'driver' => 'local',
            'root' => './../../public_html/youraddress',
            'throw' => false,
        ],
    

    Now, your files are uploaded to this directory.

    Hope it will help.