nextcloud/all-in-one · error · InvalidSettingConfigurationException

Failed to write temporary config file: ${tempFile}

Error message

Failed to write temporary config file: ${tempFile}

What it means

Thrown when file_put_contents fails to write configuration.json.tmp, the staging file used to keep config writes atomic. The temp file is unlinked on failure, leaving the original config untouched. It indicates a low-level I/O problem rather than bad input: permissions, read-only filesystem, I/O errors, or disk that filled between the free-space check and the write.

Source

Thrown at php/src/Data/ConfigurationManager.php:855

        if ($this->config === []) {
            return;
        }
        $df = disk_free_space(DataConst::GetDataDirectory());
        $content = json_encode($this->config, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);
        $size = strlen($content) + 10240;
        if ($df !== false && (int)$df < $size) {
            throw new InvalidSettingConfigurationException(DataConst::GetDataDirectory() . " does not have enough space for writing the config file! Not writing it back!");
        }
        // Write to a temp file first to avoid truncating the config file if the
        // disk fills up mid-write. rename() is atomic on POSIX filesystems, so the
        // original config is never touched until the new content is fully on disk.
        $tempFile = DataConst::GetConfigFile() . '.tmp';
        if (file_put_contents($tempFile, $content) === false) {
            // The file probably wasn't created, but better check nonetheless.
            if (file_exists($tempFile)) {
                unlink($tempFile);
            }
            throw new InvalidSettingConfigurationException("Failed to write temporary config file: " . $tempFile);
        }
        if (!rename($tempFile, DataConst::GetConfigFile())) {
            unlink($tempFile);
            throw new InvalidSettingConfigurationException("Failed to rename " . $tempFile . " to " . DataConst::GetConfigFile());
        }
        $this->config = [];
    }

    private function getEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string {
        $envVariableOutput = getenv($envVariableName);
        $configValue = $this->get($configName, '');
        if ($envVariableOutput === false) {
            if ($configValue === '') {
                return $defaultValue;
            }
            return $configValue;
        }

View on GitHub (pinned to 6b788eec5e)

Solutions

  1. Check the exact path in the message inside the container: `docker exec nextcloud-aio-nextcloud touch <path>.tmp`.
  2. Fix ownership/permissions of the data directory so the AIO container user can create files.
  3. Remount the filesystem read-write or fix the NFS/quota issue; re-check free space (df).
  4. Look for SELinux denials (`ausearch -m avc`) and label the mount correctly.
Defensive patterns

Strategy: try-catch

Validate before calling

$tmp = DataConst::GetConfigFile() . '.tmp';
if (!is_writable(dirname($tmp))) {
    // fix permissions before attempting config changes
}

Try / catch

try {
    $configurationManager->timezone = 'Europe/Berlin';
} catch (\AIO\Data\InvalidSettingConfigurationException $e) {
    if (str_contains($e->getMessage(), 'Failed to write temporary config file')) {
        // I/O problem: check perms/ro-mount/disk, original config untouched
    }
}

Prevention

When it happens

Trigger: Committing any config change while the data directory (or its parent filesystem) denies writes: directory owned by root while the PHP process runs as www-data, a read-only mount, SELinux/AppArmor denial, or a race where the disk filled after the disk_free_space check passed.

Common situations: Data directory chowned incorrectly after a manual restore; bind mount mounted ro; SELinux enforcing on CentOS/RHEL without proper labels; NFS stale-handle or quota exceeded; host disk filled mid-request.

Related errors


AI-assisted analysis of nextcloud/all-in-one@6b788eec5e (2026-08-21). Data as JSON: /api/errors/51cda9f41abbe61c. Report an issue: GitHub.