# Big-Files upload

To enable big files management, there are several components need to be fine-tuned.

Good practise is to backup configuration file by copying and renaming it by adding timestamp prefix.
Also, duplicate the line to be modified and add timestamped and signed comment.


# Prepare location for temporary storage
Ensure, disk used has enough storage to allocate for temporary file (if limit of the big file is 16GB, it must be 16GB (per one upload process, if two users upload two files, it should be double).
```bash
export host="$(hostname)"
export dir="/mnt/${host}-data/ncp1/tmp/"
mkdir -p ${dir}/php-fpm/
mkdir -p ${dir}/nginx/
df -h ${dir}
chmod 775 ${dir}/php-fpm/
chmod 775 ${dir}/nginx/
chown -R www-data:www-data ${dir}

ls -latr ${dir}
```


First, let's see current settings, which will be modifed, note them, adjust values and extract them again. By doing so, we ensure that new values are applied. This facilitate troubleshooting.

# PHP (php-fpm)

Initally, it is important to understand that 'php' and 'php-fpm' are to different packages AND configuration files are different for them as well.

To show PHP related info is to enable show php button in the admin page. The reason to use it that exactly like that PHP modules and versions are seen from application perspective. System might have packages installed, but for some reason are not seen by application. But..
```bash
root@(host):/var/www/nextcloud# sudo -u www-data php ./occ config:app:set --value=yes serverinfo phpinfo
```
```
Config value 'phpinfo' for app 'serverinfo' is now set to 'yes', stored as mixed in fast cache
```
The PHP info will be displayed on admin page, navigate to:
```
https://(nextcloud)/settings/admin/serverinfo
```
Click on "Show phpinfo()". Search for (CTRL+F or CMD+F in Firefox) "configuration file", which will indicate which file to modify. In my case, it is
```
Configuration File (php.ini) Path  /etc/php/8.3/fpm
Loaded Configuration File          /etc/php/8.3/fpm/php.ini 
```


We are interested in values defining max filesize and timeouts (in seconds)

Let's modify these values. Backup first, then load editor
```bash
file="/etc/php/8.3/fpm/php.ini"
cp ${file} ${file}.$(date +"%Y-%m-%d.%H%M")
ls -latr ${file}*

vi ${file}
```

Duplicate, modify, comment and save file. Final result and documenting style should be as below
```bash
# max_execution_time = 30
# 2025-03-23  * for big files /A
max_execution_time = 3600

# max_input_time = 60
# 2025-03-23  * for big files /A
max_input_time = 60

# memory_limit = 128M
# 2025-03-23  * for big files /A
memory_limit = 1G

# post_max_size = 8M
# 2025-03-23  * for big files /A
post_max_size = 16G

# a;upload_tmp_dir =
# 2025-03-23  * for big files /A
upload_tmp_dir = /mnt/gcp1ncp1app1-data/ncp1/tmp/php-fpm/

# upload_max_filesize = 2M
# 2025-03-23  * for big files /A
upload_max_filesize = 16G
```
Restart php-fpm
```bash
systemctl restart php8.3-fpm
```



# Webserver (nginx):

```bash
root@(host):/home/anton# vi /etc/nginx/sites-enabled/(host).conf
```
```bash
    # 2025-03-23  * for big files /A
    # client_max_body_size 512M;
    client_max_body_size 16G;
    # client_body_timeout 300s;
    client_body_timeout 3600s;

    # 2025-03-23  * for big files /A
    client_body_temp_path /mnt/gcp1ncp1app1-data/ncp1/tmp/nginx/;
```


# Application

Adjusting chunk size (use smaller chunks for higher bandwidth). In this example it will be set to 20 MB, default is 100 MB. ```--value 0``` for no chunking.
```bash
cd /var/www/nextcloud/
sudo -u www-data php occ config:system:get files.chunked_upload.max_size
sudo -u www-data php occ config:system:set --type int --value 20971520 files.chunked_upload.max_size
```
```
System config value files.chunked_upload.max_size set to integer 20971520
```
```bash
sudo -u www-data php occ config:system:get files.chunked_upload.max_size
```
```
20971520
```




ref.
```
https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/big_file_upload_configuration.html
```