# NextCloud customization

## Introduction

The solution indicated here works on a [turnkeylinux LXC image for NextCloud](https://www.turnkeylinux.org/nextcloud).

## Change the data location

To change the data location, you need to do a few things:

1. copy the previous storage location to the new one:
   ```Bash
    sudo cp -R /var/www/nextcloud-data/* /path/to/your/data/directory/
    ```
2. create a `.ncdata` file in the new data location:
   ```Bash
   vim .ncdata
   ```
   And write the following inside:
   ```
   # Nextcloud data directory
   ```
3. change the ownership of the new data directory to `www-data`:
    ```Bash
   sudo chown -R www-data:www-data /path/to/your/data/directory
   ```
4. edit the `/var/www/nextcloud/config/config.php` file:
   ```php
    <?php
    $CONFIG = array (
      'passwordsalt' => 'salt',
      'secret' => 'secret',
      'trusted_domains' =>
      array (
        0 => 'localhost',
        1 => 'example.com',
      ),
    
    ## data directory path ###########################################################################
      'datadirectory' => '/var/www/nextcloud-data',#  <---- change that to '/path/to/your/data/directory'
      'dbtype' => 'mysql',
      'version' => '30.0.0.14',
      'overwrite.cli.url' => 'http://example.com',
      'overwriteprotocol' => 'https',
      'dbname' => 'nextcloud',
      'dbhost' => 'localhost',
      'dbport' => '',
      'dbtableprefix' => 'oc_',
      'mysql.utf8mb4' => true,
      'dbuser' => 'nextcloud',
      'dbpassword' => 'password',
      'installed' => true,
      'instanceid' => 'id-number',
      'memcache.local' => '\\OC\\Memcache\\Redis',
      'redis' =>
      array (
        'host' => '/var/run/redis/redis.sock',
        'port' => 0,
        'timeout' => 0.0,
      ),
      'filelocking.enabled' => true,
      'memcache.locking' => '\\OC\\Memcache\\Redis',
      'log_type' => 'file',
    
    ## log file path #################################################################################
      'logfile' => '/var/www/nextcloud-data/nextcloud.log',# <------ change that to '/path/to/your/data/directory/nextcloud.log'
      'loglevel' => 3,
      'maintenance' => false,
      'theme' => '',
      'updater.secret' => 'secret',
    );
    ```

## Disable the HTTP to HTTPS redirection

> ⚠️
> ONLY DO THAT IF YOU HAVE A VERY VALID REASON TO!
>
> In my case, the NextCloud server is behind `HAProxy` who is set to offload the SSL encryption from the server and managing the certificates at the same time.

If NextCloud is served by `Apache2`, then this is the solution:

Edit the file `/etc/apache2/sites-available/nextcloud.conf`:
```
ServerName localhost

<VirtualHost *:80>
    UseCanonicalName Off
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/nextcloud/ # <--------- Add this line
#    RewriteEngine On   <-------- Delete or comment this line like it is here
#    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]   <-------- Delete or comment this line like it is here
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/nextcloud/

    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>
</VirtualHost>

<Directory /var/www/nextcloud/>
    Options +FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
```
Restart `apache2` service:
```Bash
sudo systemctl restart apache2
```