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

theUnforgiven's avatar

Forge - 502 Bad Gateway

Although I have the following set in my config file.

max_execution_time = 900

; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
; long running scripts.
; Note: This directive is hardcoded to -1 for the CLI SAPI
; Default Value: -1 (Unlimited)
; Development Value: 60 (60 seconds)
; Production Value: 60 (60 seconds)
; http://php.net/max-input-time
max_input_time = 60

; Maximum input variable nesting level
; http://php.net/max-input-nesting-level
;max_input_nesting_level = 64

; How many GET/POST/COOKIE input variables may be accepted
; max_input_vars = 1000

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 512M


post_max_size = 125M

file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 512M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

But still I'm trying to upload a csv file that is 9MB in size and it does upload about 75% of it, but then returns a 502

0 likes
32 replies
Dave_Martin's avatar

If you are using Apache did you restart Apache after changing the PHP ini file? Are you sure Apache is looking at the right PHP file? Does the form itself allow for files that large?

bashy's avatar

Forge uses Nginx @Dave_Martin

  1. How long is it taking to upload?
  2. Have you checked nginx error log?
  3. Have you tried setting this higher? max_input_time = 60
theUnforgiven's avatar

@bashy I have set max input time to 60 and the log shows:

2015/04/08 16:56:11 [error] 6385#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 00.00.00.0, server: default, request: "POST /admin/books/upload HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "000.00.00.0, referrer: "http://000.00.00.0/admin/books/upload"
theUnforgiven's avatar

@bashy It's taking a minute or so then going to the 502 Bad Gateway page and the file I'm trying to upload is just over 8MB.

bashy's avatar

Looks like max_input_time has no bearing on the time taken to process an upload coming from a user.

Not sure what's wrong.

theUnforgiven's avatar

Anyone else encountered this problem with uploading big files on Forge?

fideloper's avatar

Nginx has a client_max_body_size parameter which defaults to 1mb.

Your PHP configuration looks good, assuming you've restarted PHP-FPM after specifically editing /etc/php5/fpm/php.ini, I'd guess this directive for Nginx needs adding/updating to something higher.

bashy's avatar

Have you tried to see what amount you can upload without it breaking? Maybe you can find something related to the maximum that works from that.

theUnforgiven's avatar

I tried a smaller version of the file just under 1MB and it worked.

Then I tried the larger file and it still shows 502, but yet actually uploads the 15k rows from the CSV file.

theUnforgiven's avatar

Got this fastcgi_read_timeout 300; set and all the other stuff too, it does upload the file and imports the 15K rows into the db but still shows the 502 error like it's timing out.

bashy's avatar

Sounds like maybe a code issue. Does/did it work elsewhere?

fideloper's avatar

I've had issue where processes don't get stopped correctly by sysv/upstart (etc).

Stop PHP and Nginx by running: sudo service php5-fpm stop and sudo service nginx stop and then check to see if there are still nginx or php processes running:

ps aux | grep php
ps aux | grep nginx

You should just see results of you searching for those, and/or perhaps a queue if you have one running. If you see Nginx or PHP-FPM processes still running, kill them by process ID (the left farthest number):

# Kill process 1234
# use kill -9 1234 if this doesn't work:
kill 1234

What happens is that Nginx/php config doesn't get reloaded because these run-away processes aren't killed/restarted by normal operation. This has happened to me several times before on any number of servers, and is always super annoying because everything seems to operate properly, except your new configuration doesn't get taken into account.

If this doesn't work, then I think we've exhausted the usual causes, and something else is going on that none of us are aware of.

theUnforgiven's avatar

ps aux | grep php returns forge 20752 0.0 0.0 11740 936 pts/1 S+ 15:26 0:00 grep --color=auto php

same for ps aux | grep nginx

So what does this mean @fideloper ? Is there something still running?

bashy's avatar
forge 20752 0.0 0.0 11740 936 pts/1 S+ 15:26 0:00 grep --color=auto php

The data returned for each one (grep stuff) is just the command you're running to find the processes. Looks like no process is running if it's just the grep one.

1 like
tjmapes's avatar

Any update on this? I have the same thing, just on one page (502 Bad Gateway) on Forge. Locally it works just fine.

10yearsAfter's avatar

little late, but I have local the same problem and utf8_encode for some columns helps me

zainiafzan's avatar

Hi anyone already had the solution for this issue? because im facing the same issue right now and had tried everything still same 502 bad gateway. @theunforgiven

atiabjobayer's avatar

Anyone found a solve to this? Been suffering with this for months. On top of that, once a page becomes 502, it does not goes back to normal until I kinda strip the whole page back.

john_zealous's avatar

The people at Laravel Forge need to address this, as I've ran into this multiple times when spinning up a Forge server for Laravel/Inertia apps. It seems the default nginx config sets the bar too low for the amount of header data that Laravel sends to the frontend for Inertia - which causes an nginx error and thus the 502.

Here is what I've been adding to the ngnix config (using Forge's editor):

    # Increased buffer sizes for Laravel + Inertia
    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    proxy_connect_timeout 300s;
    proxy_send_timeout 300s;
    proxy_read_timeout 300s;

    # FastCGI buffer settings for PHP-FPM
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_connect_timeout 300s;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300s;

And that has stoped the 502's from happening

1 like

Please or to participate in this conversation.