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

nikhil_lu210's avatar

Laravel Project Deployment Problem in Shared Hosting (000webhost)

I have Deployed a Laravel Project on a shared hosting "www.000webhost.com". But There is some problem here that I'm facing now. The Problems are:

  1. Image Upload (Images are not storing in database & public folder)
  2. Mail Not sending.

Can anyone please give me the solution...?

if ($request->hasfile('avatar')){  
            $image = $request->file('avatar');
            $filename  = time() . 'pp.' . $image->getClientOriginalExtension();
            $location = base_path().'/images/' . $filename;
            Image::make($image)->save($location);
            $user->avatar = $filename;               
        }
0 likes
9 replies
Snapey's avatar

try public_path() and not base_path()

if you have installed Laravel securely, base_path() . '/images/' should not be accessible to users

1 like
nikhil_lu210's avatar

@snapey I have also tried this. And its working on localhost, but not in webhost..

$user = User::find(Auth::user()->id);
        if($request->hasFile('avatar')){
            
        $path = time().'.'.$request->avatar->getClientOriginalExtension();
        $request->avatar->move(public_path('images'), $path);
  
        $user->avatar = $path;
         }
Snapey's avatar

You are going to have to investigate what 'not working' means in more detail?

Any errors logged?

Do you go inside the if statement?

is public_path('images') writeable by the web server?

nikhil_lu210's avatar

@snapey , No. it's not triggering the if condition. And, the public_path('images') aren't writeable by the server

nikhil_lu210's avatar

@gurur this is my .htaccess file code:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Snapey's avatar

no, unlikely .htaccess

anyway, you said, server cannot write to public folder.

hfalucas's avatar

the public_path('images') aren't writeable by the server

Email the host asking to give you permissions or maybe try to upload the files to an AWS S3 bucket? lol

Please or to participate in this conversation.