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

codelumina's avatar

Laravel 8 spatie backup not working on server

hi, I'm using Laravel 8. when I call Artisan::call('backup:run'); in controller, it's worked on localhost but it's not working on the server. it's showing me this error message Address in mailbox given [] does not comply with RFC 2822, 3.6.2.

To the server i changed MAIL_MAILER smtp to sendmail in .env and mail.php and mail is sending without any issue. I'm using laravel 8 version. Thanks in advanced

0 likes
29 replies
codelumina's avatar

now I configured the mail recipients properly now it's showing The file "" does not exist

codelumina's avatar

i'm using this code

$path = storage_path('app/Laravel/*'); $latest_ctime = 0; $latest_filename = ''; $files = glob($path); foreach($files as $file) { if (is_file($file) && filectime($file) > $latest_ctime) { $latest_ctime = filectime($file); $latest_filename = $file; } } return response()->download($latest_filename);

It's showing me The file "" does not exist

Sinnbeck's avatar

Try wrapping the first part here in () to force early evaluation

 if ((is_file($file)) && filectime($file) > $latest_ctime) {
codelumina's avatar
$path = storage_path('app/Laravel/*');
        $latest_ctime = 0;
        $latest_filename = '';
        $files = glob($path);
         if ((is_file($file)) && filectime($file) > $latest_ctime) {
            foreach($files as $file)
            {
                if (is_file($file) && filectime($file) > $latest_ctime)
                {
                        $latest_ctime = filectime($file);
                        $latest_filename = $file;
                }
            }
            return response()->download($latest_filename);
            
         }
Sinnbeck's avatar

@codelumina Why are you wrapping the foreach in a check on $file with it isnt set?

$path = storage_path('app/Laravel/*');
        $latest_ctime = 0;
        $latest_filename = '';
        $files = glob($path);

            foreach($files as $file)
            {
                if ((is_file($file)) && filectime($file) > $latest_ctime)
                {
                        $latest_ctime = filectime($file);
                        $latest_filename = $file;
                }
            }
            return response()->download($latest_filename);

And if you are still getting an error, it should point out what line the error is on

Sinnbeck's avatar

@codelumina what line?

And if you are still getting an error, it should point out what line the error is on

codelumina's avatar

there is no line error only showing The file "" does not exist

codelumina's avatar

i just realized when i call Artisan::call('backup:run'); than no zip file is creating in storage/app/Laravel

Sinnbeck's avatar

@codelumina If you look to the left there is a row in the stack trace. 46 app/Http/Controllers..etc. Click that and see which line it is

Sinnbeck's avatar

@codelumina Ah yes. So if no file is found, you cannot download any

if (! $latest_filename) {
    return 'NO FILES EXISTS!';
}
return response()->download($latest_filename);
Sinnbeck's avatar

@codelumina Didnt you already say why that is?

i just realized when i call Artisan::call('backup:run'); than no zip file is creating in storage/app/Laravel

codelumina's avatar

why it's not creating zip and showing no error

Sinnbeck's avatar

@codelumina Did some digging. Try this in production

Artisan::call('backup:run');
dd(Artisan::output());

Should give you the output of the command. My bet is that it fails. Maybe it does not have write access to the Laravel folder

codelumina's avatar

can you please tell me another way to get database backup

Sinnbeck's avatar

@codelumina I personally use the backup service that is included with ploi.io. They setup my servers, handle my deployments and backups (+ many other things)

Please or to participate in this conversation.