@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 203 lines 7.7 kB view raw
1@title Configuring File Storage 2@group config 3 4Setup file storage and support for large files. 5 6Overview 7======== 8 9This document describes how to configure Phorge to support large file 10uploads, and how to choose where Phorge stores files. 11 12There are two major things to configure: 13 14 - set up PHP and your HTTP server to accept large requests; 15 - choose and configure a storage engine. 16 17The following sections will guide you through this configuration. 18 19 20How Phorge Stores Files 21============================ 22 23Phorge stores files in "storage engines", which are modular backends 24that implement access to some storage system (like MySQL, the filesystem, or 25a cloud storage service like Amazon S3). 26 27Phorge stores large files by breaking them up into many chunks (a few 28megabytes in size) and storing the chunks in an underlying storage engine. 29This makes it easier to implement new storage engines and gives Phorge 30more flexibility in managing file data. 31 32The first section of this document discusses configuring your install so that 33PHP and your HTTP server will accept requests which are larger than the size of 34one file chunk. Without this configuration, file chunk data will be rejected. 35 36The second section discusses choosing and configuring storage engines, so data 37is stored where you want it to be. 38 39 40Configuring Upload Limits 41========================= 42 43File uploads are limited by several pieces of configuration at different layers 44of the stack. Generally, the minimum value of all the limits is the effective 45one. 46 47To upload large files, you need to increase all the limits to at least 48**32MB**. This will allow you to upload file chunks, which will let Phorge 49store arbitrarily large files. 50 51The settings which limit file uploads are: 52 53**HTTP Server**: The HTTP server may set a limit on the maximum request size. 54If you exceed this limit, you'll see a default server page with an HTTP error. 55These directives limit the total size of the request body, so they must be 56somewhat larger than the desired maximum filesize. 57 58 - **Apache**: Apache limits requests with the Apache `LimitRequestBody` 59 directive. 60 - **nginx**: nginx limits requests with the nginx `client_max_body_size` 61 directive. This often defaults to `1M`. 62 - **lighttpd**: lighttpd limits requests with the lighttpd 63 `server.max-request-size` directive. 64 65Set the applicable limit to at least **32MB**. Phorge can not read these 66settings, so it can not raise setup warnings if they are misconfigured. 67 68**PHP**: PHP has several directives which limit uploads. These directives are 69found in `php.ini`. 70 71 - **post_max_size**: Maximum POST request size PHP will accept. If you 72 exceed this, Phorge will give you a useful error. This often defaults 73 to `8M`. Set this to at least `32MB`. Phorge will give you a setup 74 warning about this if it is set too low. 75 - **memory_limit**: For some uploads, file data will be read into memory 76 before Phorge can adjust the memory limit. If you exceed this, PHP 77 may give you a useful error, depending on your configuration. It is 78 recommended that you set this to `-1` to disable it. Phorge will 79 give you a setup warning about this if it is set too low. 80 81You may also want to configure these PHP options: 82 83 - **max_input_vars**: When files are uploaded via HTML5 drag and drop file 84 upload APIs, PHP parses the file body as though it contained normal POST 85 parameters, and may trigger `max_input_vars` if a file has a lot of 86 brackets in it. You may need to set it to some astronomically high value. 87 - **upload_max_filesize**: Maximum file size PHP will accept in a raw file 88 upload. This is not normally used when uploading files via drag-and-drop, 89 but affects some other kinds of file uploads. If you exceed this, 90 Phorge will give you a useful error. This often defaults to `2M`. Set 91 this to at least `32M`. 92 93Once you've adjusted all this configuration, your server will be able to 94receive chunk uploads. As long as you have somewhere to store them, this will 95enable you to store arbitrarily large files. 96 97 98Storage Engines 99=============== 100 101Phorge supports several different file storage engines: 102 103| Engine | Setup | Cost | Notes | 104|--------|-------|------|-------| 105| MySQL | Automatic | Free | May not scale well. | 106| Local Disk | Easy | Free | Does not scale well. | 107| Amazon S3 | Easy | Cheap | Scales well. | 108| Custom | Hard | Varies | Implement a custom storage engine. | 109 110You can review available storage engines and their configuration by navigating 111to {nav icon=home, name=Home > More Applications > Files > Help/Options > 112Storage Engines} in the web UI. 113 114By default, Phorge is configured to store files up to 1MB in MySQL, and 115reject files larger than 1MB. To store larger files, you can either: 116 117 - increase the MySQL limit to at least 8MB; or 118 - configure another storage engine. 119 120Doing either of these will enable the chunk storage engine and support for 121arbitrarily large files. 122 123The remaining sections of this document discuss the available storage engines 124and how to configure them. 125 126 127Engine: MySQL 128============= 129 130 - **Pros**: Low latency, no setup required. 131 - **Cons**: Storing files in a database is a classic bad idea. May become 132 difficult to administrate if you have a large amount of data. 133 134MySQL storage is configured by default, for files up to (just under) 1MB. You 135can configure it with these keys: 136 137 - `storage.mysql-engine.max-size`: Change the filesize limit, in bytes. Set 138 to 0 to disable. 139 140For most installs, it is reasonable to leave this engine as-is and let small 141files (like thumbnails and profile images) be stored in MySQL, which is usually 142the lowest-latency filestore, even if you configure another storage engine. 143 144To support large files, increase this limit to at least `8388608` (8MB). 145This will activate chunk storage in MySQL. 146 147Engine: Local Disk 148================== 149 150 - **Pros**: Simple to setup. 151 - **Cons**: Doesn't scale to multiple web frontends without NFS. 152 153To configure file storage on the local disk, set: 154 155 - `storage.local-disk.path`: Set to some writable directory on local disk. 156 Make that directory. 157 158Engine: Amazon S3 159================= 160 161 - **Pros**: Scales well. 162 - **Cons**: Slightly more complicated than other engines, not free. 163 164To enable file storage in S3, set these keys: 165 166 - `amazon-s3.access-key`: Your AWS access key. 167 - `amazon-s3.secret-key`: Your AWS secret key. 168 - `amazon-s3.region`: Your AWS S3 region. 169 - `amazon-s3.endpoint`: Your AWS S3 endpoint. 170 - `storage.s3.bucket`: S3 bucket name where files should be stored. 171 172Testing Storage Engines 173======================= 174 175You can test that things are correctly configured by dragging and dropping 176a file onto the Phorge home page. If engines have been configured 177properly, the file should upload. 178 179Migrating Files Between Engines 180=============================== 181 182If you want to move files between storage engines, you can use the `bin/files` 183script to perform migrations. For example, suppose you previously used MySQL but 184recently set up S3 and want to migrate all your files there. First, migrate one 185file to make sure things work: 186 187 phorge/ $ ./bin/files migrate --engine amazon-s3 F12345 188 189If that works properly, you can then migrate everything: 190 191 phorge/ $ ./bin/files migrate --engine amazon-s3 --all 192 193You can use `--dry-run` to show which migrations would be performed without 194taking any action. Run `bin/files help` for more options and information. 195 196Next Steps 197========== 198 199Continue by: 200 201 - reviewing at-rest encryption options with 202 @{article:Configuring Encryption}; or 203 - returning to the @{article:Configuration Guide}.