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

brunopincaro's avatar

Error 500 on File Uploads Over 2MB only in Production/Server

Hello everyone,

I am experiencing an issue with file uploads in Livewire on my production server.

Everything works perfectly in my local development environment, but when I try to upload files that are 2MB or larger in production, I receive a 500 Internal Server Error with the message Files.0 could not be uploaded.

Smaller files upload without any issues.

Here is my setup for both local and server/production environments:

Laravel Version: 10.48.8 PHP Version: 8.3.6 Livewire Version: 3.4.10 PHP Extensions Enabled: ctype, curl, fileinfo, etc. Server: Nginx

Livewire Configuration

'temporary_file_upload' => [
    'disk' => 'public', 
    'rules' => ['required', 'file', 'max:122880'], // 120MB
],
'max_upload_time' => 5,

Filesystem Configuration (filesystems.php):

'public' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => env('APP_URL').'/storage',
    'visibility' => 'public',
    'throw' => false,
],

PHP.ini Settings:

  • upload_max_filesize = 1G
  • post_max_size = 2G
  • realpath_cache_size = 500M

Nginx Configuration:

server {
    listen 80;
    listen 443 ssl;
    server_name ...;
    root "...";

    # Increase the maximum file upload size
    client_max_body_size 2G;

    ...
}

Despite these configurations, I am still encountering the issue. The logs do not provide more details beyond the error message mentioned above. I've also checked the file permissions and they seem to be correct.

Could anyone provide insights into what might be causing this issue or suggest further diagnostics to resolve it?

Thank you!

0 likes
5 replies
LaryAI's avatar
Level 58

It seems like the issue might be related to the server configuration, particularly with Nginx, since the error only occurs in the production environment and not locally. Given that smaller files upload without issues, the problem likely revolves around handling larger files. Here are a few steps and checks you can perform to diagnose and potentially resolve the issue:

  1. Verify Nginx Configuration: The client_max_body_size directive in Nginx determines the maximum allowed size of the client request body. Although you've set it to 2G, which should be sufficient, ensure that this directive is placed correctly in the server block or in the http context to be globally effective.

  2. Check PHP-FPM Settings (if using PHP-FPM): Sometimes, the issue might be with the PHP-FPM settings. Ensure that the request_terminate_timeout and other related timeout settings are sufficiently high to handle the upload of large files.

  3. Error Logs: Check both Nginx and PHP error logs immediately after attempting to upload a large file. These logs can provide more specific information about what is causing the error 500. Nginx logs are typically found in /var/log/nginx/error.log and PHP logs location can vary based on configuration but often found in /var/log/php-fpm/error.log.

  4. File Permissions and Ownership: Double-check the permissions and ownership of the directories where files are being uploaded, especially the storage/app/public directory in Laravel. Ensure that the web server user (often www-data on Ubuntu servers) has write permissions to these directories.

  5. PHP Configuration: Although your php.ini settings seem correct, verify them on the server by creating a simple PHP file with phpinfo(); and accessing it from a browser. This will show you the actual values that PHP is using, which might differ from your php.ini file if the wrong file is being edited or settings are being overridden somewhere else.

  6. Livewire Specific Configuration: Check if there's any Livewire specific configuration that might be affecting file uploads. Since Livewire handles file uploads in a slightly different manner, ensure that all configurations under temporary_file_upload are correct and supported by the server environment.

  7. Increase PHP Memory Limit: Sometimes, memory limitations might cause large file uploads to fail. Increase the memory_limit in your php.ini file to a higher value and see if that resolves the issue.

  8. Debugging Further: If none of the above steps work, you might need to debug deeper by temporarily modifying the Livewire component to log more detailed error messages or by stepping through the code with a debugger.

Here's a quick check you can add to your Nginx configuration to ensure the client_max_body_size is set correctly:

http {
    client_max_body_size 2G; # This needs to be here or in the specific server block

    server {
        listen 80;
        listen 443 ssl;
        server_name ...;
        root "...";

        ...
    }
}

And ensure your PHP-FPM pool configuration (often found in /etc/php/8.3/fpm/pool.d/www.conf or similar) has appropriate timeout settings:

request_terminate_timeout = 300s

By following these steps, you should be able to pinpoint the cause of the issue or resolve it.

amitsolanki24_'s avatar

Try to set upload max size to 1000M

upload_max_filesize = 1000M
post_max_size= 1000M
Snapey's avatar

check your livewire config is seen with tinker

>>> config('livewire');
brunopincaro's avatar

@Snapey it sees it.

Running config('livewire') on the server got the following output:

> config('livewire');
= [
    "class_namespace" => "App\Livewire",
    "view_path" => "/var/www/webapp/resources/views/livewire",
    "layout" => "components.layouts.app",
    "lazy_placeholder" => null,
    "temporary_file_upload" => [
      "disk" => "public",
      "rules" => [
        "required",
        "file",
        "max:122880",
      ],
      "max_upload_time" => 5,
    ],
    "render_on_redirect" => false,
    "legacy_model_binding" => false,
    "inject_assets" => true,
    "navigate" => [
      "show_progress_bar" => true,
      "progress_bar_color" => "#22C55E",
    ],
    "inject_morph_markers" => true,
    "pagination_theme" => "tailwind",
]
brunopincaro's avatar
brunopincaro
OP
Best Answer
Level 26

Figured it out.

Did php -i in terminal to see what php.ini was being loaded but dd(phpinfo()); gave me a different php.ini. Making the changes in this last one fixed the issue.

Please or to participate in this conversation.