How do I enable error reporting in Laravel?

How do I enable error reporting in Laravel?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

How do I enable error reporting in Laravel?

When processing large datasets, such as an Excel sheet with over 18,000 records, a generic HTTP 500 error is often unhelpful. It tells you the server crashed but hides the actual cause. In the scenario where max_execution_time adjustments fail and logs reveal a "Fatal error: Allowed memory size... exhausted," the issue isn't about enabling general error reporting; it is specifically about configuring how Laravel and PHP report fatal errors.

By default, many production environments (and some local setups like XAMPP or WAMP) suppress fatal errors to prevent crashes. To see the real stack trace and understand where memory was exhausted, you must modify php.ini and ensure Laravel's exception handler is configured to display these details during development.

Configuring PHP Memory Limits

The error log explicitly states: Allowed memory size of 134217728 bytes exhausted. This corresponds to 128 MB. When importing 18,000 rows into a single collection or loop without pagination, you can easily exceed this limit because Laravel loads the entire dataset into memory before processing.

You have two primary levers to pull here: increasing the memory limit and changing how fatal errors are handled.

1. Adjust php.ini Settings

Simply editing max_execution_time does not solve a memory exhaustion issue; it only extends the time PHP waits before killing the script due to CPU usage. You must increase the memory allowance.

Locate your php.ini file. Depending on your stack (Apache, Nginx with PHP-FPM, or XAMPP), this might be in:

  • C:\xampp\php\php.ini
  • /etc/php/7.x/apache2/php.ini
  • Or a dedicated custom.ini inside the web root if loaded via Apache config.

Add or modify these directives:

memory_limit = 512M
max_execution_time = 300
upload_max_filesize = 10M
post_max_size = 10M

Crucial Distinction: If you are running on Apache with mod_php, changes here apply immediately. However, if you are using PHP-FPM (common in production and increasingly common locally), editing the global php.ini might not affect your application. You must edit the specific pool configuration file (e.g., www-pool.conf) located in /etc/php/7.x/fpm/pool.d/.

Configuring Laravel to Display Errors

Even with increased memory, if you want to see the exception message rather than a generic "500 Internal Server Error" page, you must enable error reporting within Laravel itself. This is done via the .env file and configuration files.

Enabling Debug Mode

Ensure your environment is set to development:

APP_ENV=local
APP_DEBUG=true

When APP_DEBUG is true, Laravel serves a detailed error page with the stack trace, file paths, and line numbers. If this flag is false or missing, Laravel will display a generic layout, hiding the specific memory exhaustion message in the browser even if PHP logs show it.

Handling Fatal Errors

The log entry PHP Fatal error: Allowed memory size... indicates that the script crashed before Laravel's exception handler could catch and format the error gracefully. This is different from a standard Exception.

To ensure fatal errors are logged (and potentially caught, though difficult for memory exhaustion), check your config/app.php file. Ensure the following settings align with your needs:

'exceptions' => [
    'handler' => \Monolog\Handler\StreamHandler::class,
],

More importantly, ensure that APP_DEBUG is active. If you are stuck on a localhost with an Apache 500 error page, verify that the .htaccess file is not overriding Laravel's debug settings or blocking detailed logs.

Solving the Memory Exhaustion Root Cause

Increasing limits is a temporary fix. The architectural solution for processing 18,000 records involves breaking the operation into chunks. Loading all rows into memory at once will almost certainly exhaust the heap regardless of the memory_limit setting.

Use Laravel's built-in chunking or queue jobs:

// Process in chunks of 250
$users = User::chunk(250, function ($users) {
    // Process $users here
    // Do not load all users into memory
});

Alternatively, offload the heavy lifting to a queue worker. This allows PHP-FPM to handle other requests while your import job processes data asynchronously, preventing the web server from crashing under the weight of long-running scripts.

Conclusion

If you are seeing a generic 500 error on localhost, enabling APP_DEBUG=true in your .env file is the first step to revealing the underlying cause. Once the error message confirms memory exhaustion, increasing memory_limit in php.ini provides immediate relief. However, for large imports like 18,000 records, relying solely on increased limits is inefficient; implementing chunking or queue-based processing ensures your application remains stable regardless of dataset size.

Our network