Gateway Timeout when updating Nextcloud

The Nextcloud update server seems to be suffering from high load at times, resulting in gateway timeout. Here is how to fix that annoying problem.


Edited: 2021-02-22 20:29

When trying to update Nextcloud you might run into a 504 Gateway Timeout error; this might happen either because your server is too slow, or because the server you are downloading the update from is too slow.

Last time this happened to me, it was because the update server was too slow, and when the update does not finish downloading in time, it might result in an error like:

Step 4 is currently in process. Please reload this page later.

Instead of trying to resume the update from the web- interface, you should consider updating from terminal.

Step 4 is currently in process

First time I had this problem, I had to go to my terminal and manually download the update .zip file with the wget command in the data/updater-xxxxxx/downloads/ directory.

After having downloaded the file manually, I edited the .step file and change the state from start to end. E.g.:

{"state": "end", "step":4}

This caused Nextcloud to finish the update process using my manually downloaded file.

Note. This did not work the second time. Instead, I had to use the command line tool.

Updating using the command line tool

Because the updater is stuck on step 4, you need to delete the .step file in data/updater-xxxxxx/; note that the file is hidden, so in order to list it you have to use ls -al.

sudo rm .step

Then, to update from terminal:

sudo -u www-data php /var/www/nextcloud/updater/updater.phar

Note. If your server is running multiple versions of PHP you should replace php with the version of PHP your Nextcloud installation is using. I.e: php7.4

After updating you may be asked if ./occ upgrade should be run, but if you have multiple versions of PHP this will fail because the occ tool picks the wrong version. Instead, run the command manually:

sudo -u www-data php7.4 /var/www/nextcloud/occ upgrade

If you need to disable maintenance mode after updating:

sudo -u www-data php7.4 /var/www/nextcloud/occ maintenance:mode --off

If you dislike using the terminal to update, you may also be able to fix the web-based updater by setting max_execution_time to unlimited; this can be done in your php.ini file or in a custom settings file.

Read: Should You Edit conf.d Files or php.ini?

A possible solution

It is possible to perform a chunked download using AJAX and PHP.

As a potential solution, if a developer happens to read this, I would suggest sending a series of HTTP request from the Nextcloud front-end to a PHP script that will then download the file in chunks using range requests.

Perhaps something along those lines could be implemented so people do not have to edit their php.ini; alternatively, it is also possible to change the max_execution_time from within PHP on servers that permit it. E.g.:


Doing so would prevent the setting from influencing all of the running scripts on the server.

Tell us what you think:

  1. How to setup a redirect for webfinger and nodeinfo in your server configuration to make Nextcloud stop complaining about it.
  2. Sometimes you might encounter compatibility problems with Nextcloud when updating to the latest version of PHP, luckily we can just run multiple versions of PHP on the same server.
  3. This tutorial explains how to install Nextcloud on the Apache HTTP server in Linux.

More in: Nextcloud