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

Lugi's avatar
Level 21

Malicious files found in Laravel public folder - how can I disable it ?

Hello all,

I have a website which was written in Laravel 5. I found malicious files in folders: public_html and mylaravelproject\public. I'm not sure how this happened because I don't use upload file functionality anywere. Anyway, I restored this folders from backup and now website is running fine. To avoid future issues, I deleted all contact forms and auth paths from source code so webpage is now more or less just showing static pages like About Me, etc... But that's fine because in the future I have plan to rebuild everything.

But until rebuilding, I want to run current website as it is.

Based on last modified date my conclusion is that the entry point was mylaravelproject\public folder. So, to keep the website safe until rebuilding, I want to completely disable this folder.

Please suggest how can I disable Laravel public folder (mylaravelproject\public)

If this helps, I provide some config details:

  • laravel project folder is outside of public_html
  • .htaccess config is like this:
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # 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]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
  • here is filesystems.php:
<?php
return [
    'default' => env('FILESYSTEM_DRIVER', 'local'),
// ...
    'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],
        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
    // ...
0 likes
9 replies
neilstee's avatar

@lugi

Malicious files found in Laravel public folder

Via what? If this is a program to protect your files it thinks JS or any code can be harmful, but if you know what you are doing then disable that path entirely.

You also said you don't upload user files on that folder so I think nothing to worry about here.

neilstee's avatar

I wanted to say A N T I V I R U S but Laracasts is preventing me from typing it, it thinks its a spam πŸ˜…

Lugi's avatar
Level 21

I found a malicious php file there in mylaravelproject\public. I have no idea how it ended there.

You said to disable the path entirely, but I don't have path to public anyway...

Btw, AV anyway found nothing even after my site was down (replaced with ssi.shtml)...

1 like
ahmeddabak's avatar

I have also found Malware files in my public folder, I have my project on a digital ocean droplet, no idea how this could have happened.

Lugi's avatar
Level 21

All my Laravel projects were hacked at the end. Sorry to say that but I switched to other programming language and framework. Now at the end I think it may be related to PHP/Laravel mail sending capabilities which from security point should not be present on the server out of the box (that's my opinion, but maybe I'm wrong).

ahmeddabak's avatar

I thought so at the beginning, and I checked many times. But it is not the case here for many reasons.

Maybe a vulnerable composer package, or a Linux exploit.

Please or to participate in this conversation.