Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cd4success's avatar

How can I tell Laravel to look for public_html folder and not public folder on SHARED HOSTING?

I am trying to update profile picture on a small laravel app but server returns 500 SERVER ERROR due to wrong directory structure. I have done some googling but most answers were 6, 5, 4, 3 and 2 years old. I'm using laravel 8. Here's my controller....

Thanks

      public function updateAvatar()
    {
        //  dd(request('avatar'));
         $theUser = Auth::user();

         request()->validate([
             'avatar' => 'image|max:1000'
         ]);
 
         // File upload
         if (request()->hasFile('avatar')){

            $path = request()->file('avatar')->storeAs('uploads', $request->file('avatar'));
 
             $profileImage = Image::make(public_path('storage/' . $path))->fit(40,40);   
              
                       // On the server: I have public_html/storage

             $profileImage->save();
         }
         else{
             $path = $theUser->avatar;
         }
   
         $theUser->update([
             'avatar' => $path,
             ]);
         
             
 
         request()->session()->flash(
             'message', 'Your avatar was successfully updated.'
         );
 
         return redirect()->back();
    }
0 likes
2 replies
gitwithravish's avatar

Please show the following details so that anyone can understand.

  • Your folder structure
  • Error message
  • Do you have a storage link to of storage folder to public folder or you are trying to access app/storage folder @cd4success
cd4success's avatar

Thanks a lot, @gitwithravish.

Here's my remote server folder structure

MyLaravelApp
-app
-bootstrap
-config
-database
-public
-resources
-routes
-storage
-tests
-vendor
.editorconfig
.env
.env.example
.gitattributes
.gitignore
.styleci.yml
artisan
composer.json
composer.lock
package.json
phpunit.xml
readme.md
server.php
webpack.mix.js


public_html
-css
-js
-background_images
-storage (symlink already created) - inside this folder I have "photo.jpg" as default
-favicon_package
.htaccess
-favicon.ico
-index.php
-robots.txt
-web.config


Error log message: Cannot serve directory /home/my-username/public_html/storage/public/: No Matching DirectoryIndex 


And page shows 500 SERVER ERROR.

Please or to participate in this conversation.