NextCloud: Install: Heroku

From Gratiel's Wiki
Revision as of 18:42, 21 June 2019 by Ewanchic (talk | contribs) (→‎Add ghost files)

Preface

  • Ephemeral Drive
    • Locked Code
    • S3
  • Databases
    • PostgreSQL

Prerequisites

You are going to need the following Services and Software before getting started with your NextCloud installation on Heroku. 

Be sure you have accounts setup for the following Services listed below. 
Also, be sure you have installed the following Software listed below.

Services

Software

sudo snap install heroku --classic

Setup Heroku

Login to Heroku CLI (Ubuntu)

heroku login

Create App

  • This needs to be created after git. IT will automatically create the remote links needed in Git
heroku create

Heroku will return a sample app and location. Use this for the rest of the install.

Creating app... done, ⬢ infinite-lowlands-38883
https://infinite-lowlands-38883.herokuapp.com/ | https://git.heroku.com/infinite-lowlands-38883.git

Heroku Add-ons

  • Heroku Postgres

Install NextCloud - Phase 1

Download & Extract NextCloud

Download the version of nextcloud

wget https://download.nextcloud.com/server/releases/nextcloud-15.0.8.zip

Unzip nextcloud-x.x.x.zip to it's own folder

unzip nextcloud-15.0.8.zip

Create a new folder `nextcloud-x.x.x`

mkdir nextcloud-15.0.8

Move folder `nextcloud` into `nextcloud-x.x.x` and label it `server`

mv nextcloud nextcloud-15.0.8/server

Initialize Git

cd nextcloud-15.0.8
git init
git config user.name "Eric Wanchic"
git config user.email "ewanchic@elifestream.com"
cat > .gitignore

Copy & Paste the following to the file:

/vendor/
.env

Ctrl+D

git add .
git commit -m "Initial NextCloud 15.0.8"

Setup Composer

cat > composer.json

Copy & Paste the following to the file:

{
  "require" : {
    "php": "7.2.19",
    "ext-mbstring": "*",
    "ext-gd": "*",
    "ext-intl" : "*",
    "ext-imagick": "*",
    "ext-memcached": "*",
    "ext-pcntl": "*"
  },
  "require-dev": {
    "php": "7.2.19",
    "ext-mbstring": "*",
    "ext-gd": "*",
    "ext-intl" : "*",
    "ext-imagick": "*",
    "ext-memcached": "*",
    "ext-pcntl": "*"
  }
}

Ctrl+D to exit

composer update

Commit code to repo

git add .
git commit -m "Adding composer files."

Setup PHP FPM file

cat > fpm_custom.conf

Copy & Paste the following to the file:

php_value[upload_max_filesize] = 300M
php_value[post_max_size] = 200M
php_value[memory_limit] = 128M
php_value[mbstring.func_overload] = 0
php_value[default_charset] = 'UTF-8'
php_value[output_buffering] = 0

php_value[apc.enable_cli] = 1

Ctrl+D to exit

Commit code to repo

git add .
git commit -m "Adding custom php fpm."


Setup Procfile

cat > Procfile

Copy & Paste the following to the file:

web: vendor/bin/heroku-php-apache2 -F fpm_custom.conf server/

Ctrl+D to exit

You might be tempted to use nginx instead of apache. In this instance, stay with apache.

Commit code to repo

git add .
git commit -m "Adding Procfile."

Install PostgreSQL Add on

heroku addons:create heroku-postgresql:hobby-dev --app infinite-lowlands-38883

DB is created. You'll have to log in to get further details.

Creating heroku-postgresql:hobby-dev on ⬢ infinite-lowlands-38883... free
Database has been created and is available
 ! This database is empty. If upgrading, you can transfer
 ! data from another database with pg:copy
Created postgresql-crystalline-20674 as DATABASE_URL
Use heroku addons:docs heroku-postgresql to view documentation

Install NextCloud - Phase 2

Pushing Code to Heroku

git push heroku master

Do not setup the app just yet.

SSH into App

Need to SSH into Heroku after app starts.

heroku ps:exec --app infinite-lowlands-38883
Running this command for the first time requires a dyno restart.
Do you want to continue? [y/n]: y
Initializing feature... done
Restarting dynos... done
Waiting for web.1 to start... done
Establishing credentials... done
Connecting to web.1 on ⬢ infinite-lowlands-38883... 
~ $

Get the current Config

cd server/config
cat config.php
<?php
$CONFIG = array (
  'instanceid' => 'oczm2c0yitlu',
);

Create a config

cat > config.php
<?php
$CONFIG = array (
  'instanceid' => 'oczm2c0yitlu',
);

Ctrl+D

git add .
git commit -m "Initializing config.php"

Install NextCloud - Phase 3

Run the Setup

  1. Running the setup, Add username, password, and PostgreSQL information.
  2. Setup will Fail. Error: The username is already being used

Get new config file

  1. Log into Heroku again
heroku ps:exec --app infinite-lowlands-38883
Establishing credentials... done
Connecting to web.1 on ⬢ infinite-lowlands-38883... 

  1. Output config file:
<?php
$CONFIG = array (
  'instanceid' => 'oci1sj5gwidj',
  'passwordsalt' => '2YHY53pJ19z1sQH8VLlyxQnJ+G7X/n',
  'secret' => 'UWNfUzFSNDmqTLNwhtsY3FEvg8PfDND8mUfcKmBV78UQweAS',
  'trusted_domains' => 

  array (
    0 => 'infinite-lowlands-38883.herokuapp.com',
  ),
  'datadirectory' => '/app/server/data',
  'dbtype' => 'pgsql',
  'version' => '15.0.8.1',
  'overwrite.cli.url' => 'http://infinite-lowlands-38883.herokuapp.com',
  'dbname' => 'd8saj3o99k4kf6',
  'dbhost' => 'ec2-54-225-72-238.compute-1.amazonaws.com',
  'dbport' => ,
  'dbtableprefix' => 'oc_',
  'dbuser' => 'tvsinoicrvngaq',
  'dbpassword' => 'cb6e7c80e137f4dd06011f1319e1537e81066c66ec9a527fc75980b87d71de82',
);

This step not only establishes the database and site credentials (which we could have added manually), but it sets up the: username & password, password salt, and secretkey which all are encoded into the database.

We are going to need to save these values and enter them into Heroku's Config Vars.

Now we need to modify the config.php to accept environment variables:

<?php
$CONFIG = array (
  'instanceid' => 'oci1sj5gwidj',
  'passwordsalt' => getenv('PASSWORD_SALT'),
  'secret' => getenv('SECRET'),
  'trusted_domains' => 

  array (
    0 => 'infinite-lowlands-38883.herokuapp.com',
  ),
  'datadirectory' => getenv('DATA_DIRECTORY'),
  'dbtype' => 'pgsql',
  'version' => '15.0.8.1',
  'overwrite.cli.url' => 'http://infinite-lowlands-38883.herokuapp.com',
  'dbname' => getenv('DB_NAME'),
  'dbhost' => getenv('DB_HOST'),
  'dbport' => ,
  'dbtableprefix' => 'oc_',
  'dbuser' => getenv('DB_USER'),
  'dbpassword' => getenv('DB_PASSWORD'),
);


Go ahead and update the config.php on your local git repo to match this. Save and commit.

git add .
git commit -m "Updated config.php. Includes DB credentials, trusted site credentials, passwordsalt & secretkey. All important values are being replaced by Environment Variables."

Install NextCloud - Phase 4 (S3 Bucket)

  • Setup S3 Logging for two buckets
    • Actual S3 Bucket
    • The Replicated S3 Bucket
  • Setup Replication for an S3 bucket
    • Setup Versioning
    • Link the S3 Bucket to it's log
    • Block All Public Access
  • Create the S3 Bucket
    • Setup Versioning
    • Link the S3 Bucket to it's log
    • Link the S3 Bucket to replication
    • Block All Public Access
  1. Configure config.php file
<?php
$CONFIG = array (
  'instanceid' => 'oci1sj5gwidj',
  'objectstore' =>
  array (
    'class' => '\\OC\\Files\\ObjectStore\\S3',
    'arguments' =>
    array (
      'bucket' => getenv('S3_BUCKET'),
      'autocreate' => true,
      'key' => getenv('S3_KEY'),
      'secret' => getenv('S3_SECRET'),
      'use_ssl' => true,
      'region' => getenv('S3_REGION'),
      'use_path_style' => false,
    ),
  ),
  'passwordsalt' => getenv('PASSWORD_SALT'),
  'secret' => getenv('SECRET'),
  'trusted_domains' => 

  array (
    0 => 'infinite-lowlands-38883.herokuapp.com',
  ),
  'datadirectory' => getenv('DATA_DIRECTORY'),
  'dbtype' => 'pgsql',
  'version' => '15.0.8.1',
  'overwrite.cli.url' => 'http://infinite-lowlands-38883.herokuapp.com',
  'dbname' => getenv('DB_NAME'),
  'dbhost' => getenv('DB_HOST'),
  'dbport' => ,
  'dbtableprefix' => 'oc_',
  'dbuser' => getenv('DB_USER'),
  'dbpassword' => getenv('DB_PASSWORD'),
);

Go ahead and update the config.php on your local git repo to match this. Save and commit.

git add .
git commit -m "Updated config.php. Includes S3 credentials, important values are being replaced by Environment Variables."


Need to apply the patch.

git add .
git commit -m "Apply S3 Patch".

Install NextCloud - Phase 5 (Tell NextCloud that it is done installing)

Obtain config #2

git push heroku master
  • Check everything, code should be clean.
  • Reset the Database
  • Redo the install
  • Check that the S3 bucket was filled with oids.
  • look at the new config.php File

Obtain new Values

  • If there is a new config file, then redo the environment vars with:
    • Secret
    • Password-Salt

Set Install status to True

Add the new item to tell the config.php that the install is completed.

'installed' => true,
git commit -a -m "Telling NextCloud that its installation process is finished."

Configure Log Files

Add some additional information for logging purposes.

 'log_type' => 'syslog',
 'logfile' => ,
 'loglevel' => '1',
 'logdateformat' => 'F d, Y H:i:s',
git commit -a -m "Adding some additional logging parameters for nextcloud. Sending log info to syslog."

Add ghost files

mkdir -p server/data
cd server/data
touch .ocdata index.html nextcloud.log
cd ../..
git add .
git commit -m "Adding ghost files needed in ./data."

Recommit and Test

git push heroku master

Check that the login works.

Install NextCloud - Phase 6 (Security)

TOTP

  • Install TOTP
  • Enable TOTP

Users

  • Lockdown Storage

Install NextCloud - Phase 7 (S3 Storage)

Patches

Heroku

More than one MPM loaded.

Heroku - AH00534: apache2: Configuration error: More than one MPM loaded.

To fix this, you need to execute this patch to heroku:

heroku labs:enable --app infinite-lowlands-38883 runtime-new-layer-extract
Enabling runtime-new-layer-extract for infinite-lowlands-38883... done

NextCloud

S3 Issues

Commands

Heroku

Restart

heroku ps:restart --app infinite-lowlands-38883
Restarting dynos on ⬢ infinite-lowlands-38883... done

NextCloud

Backup

Restore

Upgrading

References

Return