The Problem

While uploading and resizing images in a Laravel production environment on Webuzo, the application started throwing 500 errors. The Laravel log was clear about the cause:

Allowed memory size of 67108864 bytes exhausted
(tried to allocate 40960 bytes)

The error originated inside Intervention Image's GD resize command. 67108864 bytes is exactly 64MB — the PHP default memory limit. The server was simply hitting its ceiling.

Why This Happens

When GD processes an image it doesn't work with the compressed file on disk. It decodes the full bitmap into memory first, creates a second copy for the resized output, then allocates additional temporary buffers during the operation.

💡
Memory consumption — resizing a 5MB JPEG

Compressed file on disk: ~5MB. Decoded bitmap in memory (original): ~40–60MB. Total with resized copy + buffers: 80–120MB. The 64MB limit gets hit before resizing even begins on a 3000×2000px image.

The compressed JPEG looks small, but GD needs to hold the full uncompressed pixel data — width × height × bytes per pixel — for both the source and the output simultaneously. A 3000×2000px image can easily consume 70MB+ before any resizing even begins.

Why .htaccess Didn't Work

What I tried first
php_value memory_limit 256M
Why it doesn't work
# .htaccess php_value directives
# are silently ignored by PHP-FPM
💡
mod_php vs PHP-FPM

mod_php runs as part of Apache and respects .htaccess PHP directives. PHP-FPM is a separate process manager that doesn't read .htaccess at all — it only reads php.ini and .user.ini files. Most modern Webuzo setups run PHP-FPM.

The Correct Fix

Since PHP-FPM respects .user.ini files placed in the web root, and this requires no root access, it's the right tool for the job on Webuzo.

1

Navigate to your public directory

This is wherever your Laravel app's public/ folder lives:

/home/myaccount/public_html/
2

Create .user.ini

Create a new file in that directory named exactly .user.ini. Note the leading dot — it's a hidden file.

3

Add the memory limit directive

memory_limit = 256M

Save the file. No Apache or PHP restart needed — PHP-FPM picks it up automatically, usually within 1–5 minutes.

After adding the file

Image uploads and resize operations started working immediately (after the cache TTL). No server restarts, no root access required.

While you have the file open, it's worth setting the other limits that matter for image-heavy Laravel apps:

DirectiveValueWhy
memory_limit256MGD needs full bitmap in RAM for both source and output
upload_max_filesize20MAllows reasonably large image uploads
post_max_size25MMust be larger than upload_max_filesize
max_execution_time120Prevents timeouts on slow or large image processing

Why This Is the Right Approach

  • No root access required — works on shared and managed servers
  • Works with PHP-FPM (unlike .htaccess directives)
  • No Apache or PHP service restart needed
  • Scoped to your app's directory — doesn't affect other users on the server
  • Safe and production-appropriate

TL;DR

GD decodes compressed images into full bitmaps before resizing, which can consume 10–20× the file size in RAM. The default 64MB PHP limit isn't enough. .htaccess can't fix this on PHP-FPM. Create .user.ini in your public directory, add memory_limit = 256M, done.