IT/Software/Web Applications/NextCloud

From msgwiki
Revision as of 10:27, 7 September 2023 by Walttheboss (talk | contribs) (Add Nextcloud media ffmpeg conversion script)
Jump to navigation Jump to search
Access restrictions were established for this page. If you see this message, you have no access to this page.

This is an amazing tool that as of now (March 1 2022) is getting amazingly fast development.

As with most things of this sort the prices will soon appear and it will become a paid product

Install

There are many ways to install. I prefer the apt method and NOT snap of flatpak.

sudo add-apt-repository ppa:nextcloud-devs/client -y


sudo apt install nextcloud-client -y

Configure

Make sure you have a big directory outside of www AND that the directory is web-writeable and mounted at boot.

Update

This can now(since 17) be done via the gui. Older versions need:

sudo -u www-data php /var/www/html/next.msgcnx/updater/updater.phar

To Update: Click on the picture of the main admin user. Click on Settings

Now you will see "Administration" on the left. Click on "Overview"

Read the Update Check notes carefully and attend to them one by one.

  • php version is the limit from version 19.04 on Ubuntu Server 18.04

Sometimes due to a permissions issue it will say in read that .ocdata is not there.

  • The update will still run.

If your update Hangs or fails.

Sometimes things happen.

Maybe you get this error:

Upgrade stuck at “Step 4 is currently in process. Please reload this page later”

Repair with

sudo -u www-data php /path/to/occ maintenance:repair

works for me to, but you may need to use:(specify php version)

sudo -u www-data php7.2 /path/to/occ maintenance:repair

If it is still not working you can try to run the upgrade from occ (you may need to specify phpX.X)

sudo -u www-data php /path/to/occ upgrade

If you update and then you get nothing. Just no page loads.

Try to go to the site/updater

hopefully you will get the Step 4 error message now.

There are lots of things to fix when upgrading from 19 to 20. You should add caching

  • Install APCu from the Package Manager
  • Add this line to the bottom of your /nextcloud/config/config.php

'memcache.local' => '\OC\Memcache\APCu',

Then restart apache

Buried in your php config files in mods-available is apcu.ini

Add this line

apc.enable_cli=1

Tricks

Syncing Files

  • This very important in the self hosted world. How do we put and get files outside of the app itself.
  • This can easily be done though you need root access.
  • Use rsync or similar to sync or copy programs right into the directories.
  • Then you need to run an occ (OwnCloudCommand) program with php to rescan for files. Then it will add all the files to the database.

sudo -u www-data php /var/www/html/mir.next.msgvte/occ --verbose --unscanned files:scan --all

  • -u will specify the user
  • php runs the current version of php.
  • --verbose or -V tell you more as it happens.
  • --unscanned will only check what has not been scanned. HUGE time savings.
  • files:scan is the actual command or program that runs.

Maintenance Mode

You can turn it on and off with the following command.

The command below is one of the two. We hope you can figure out which one it is and which one is the other!
sudo -u www-data php /var/www/html/next.msgcnx/occ maintenance:mode --off

Removing Errors

Invalid Modification Times

Occasionally you will sync up large unknown directories. There can be all kinds of problems with the naming and structure of the files. Two common errors are "Invalid Modification Time" and leading or trailing spaces in file names.

To fix the Modification time you can use the find command described here.

Strict Transport Headers

Add this in the ssl vhosts file.

    <IfModule mod_headers.c>

      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"

    </IfModule>

You need to enable mod_headers

sudo a2enmod headers

Allow .htaccess to be read

You need to enable the reading of and overriding by .htaccess in the vhosts file.

    <Directory /var/www/html/next.msgcnx/>

        Options Indexes FollowSymLinks

        AllowOverride All

        Require all granted

    </Directory>

You may also need to edit the .htaccess file in the root of your NextCloud instance. (this is a bit fuzzy)

I changed mine and after adding the redirects below it was changed back.

caldav and carddav errors

Sometimes these features may work even if the error persists.

Read the above section on .htaccess. That MUST be done first.

Add the following lines to vhosts ssl.conf

  Redirect 301 /.well-known/carddav https://next.msgcnx.com/remote.php/dav

  Redirect 301 /.well-known/caldav https://next.msgcnx.com/remote.php/dav

Caching

Install APCu from the package manager

Add this line to your NextCloud config.php at the bottom.

  'memcache.local' => 'OC\Memcache\APCu',

Database errors

These all have to be handled one at a time. Follow the onscreen instructions.

Integrity Check

Sometimes you change a file after an update. Its hash now doesn't match the one that NC is looking for.

this can happen with htaccess.

sudo -u www-data php /var/www/nextcloud/occ maintenance:update:htaccess

php-imagick has no SVG support

If you see an error message saying "Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it." try to install libmagickcore-6.q16-6-extra with apt-get install libmagickcore-6.q16-6-extra

sources: https://serverok.in/module-php-imagick-in-this-instance-has-no-svg-support

https://techoverflow.net/2021/08/17/how-to-fix-docker-nextcloud-module-php-imagick-in-this-instance-has-no-svg-support-for-better-compatibility-it-is-recommended-to-install-it/

Desktop Client

One error is the log files fill up the disk too fast.

They are located in /home/user/.config/Nextcloud

find /home/walt/.config/Nextcloud/logs -name '*.gz' -type f -mmin +240  -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Explanation:

  • The first argument is the path to the files. I would recommend using the full path, and make sure that you run the command first without the exec rm to make sure you are getting the right results.
  • The second argument is -name and that only looks for files matching the pattern.
  • The third argument is -type and will only look for files = f (You can use d for directory)
  • The fourth argument, -mmin, is used to specify the number of minutes old the file is.
  • The fifth argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

Change default page or landing page.

When you login it goes by default to the dashboard.

Most of us want access to our files or another app and not the weather. (we get enough of that from our colleagues)

Install the app apporder

Add one line near the bottom of config.php

'defaultapp' => 'apporder'

To run FFMPEG conversion automatically from one dir to another

This script with some modifications should be put in a root crontab to run every 5 minutes or so. It will compare and convert any files from $source_dir into $destination_dir using ffmpeg, chown them to www-data and sync the Nextcloud instance to recognize the new files. Any .mp4 files found in the destination dir without a matching .mov file will be deleted. Note the shortcut taken near the end with a manual path if using a different location.

#!/bin/bash

# Define the source and destination directories
source_dir="/media/nextcloud/msgcnx/walt/files/Teacher/Math/Algebra 1/Lesson Videos"
destination_dir="/media/nextcloud/msgcnx/walt/files/Teacher/Math/Algebra 1/PUBLIC Lesson Videos"

# Check if the source directory exists
if [ ! -d "$source_dir" ]; then
  echo "Source directory not found: $source_dir"
  exit 1
fi

# Check if the destination directory exists
if [ ! -d "$destination_dir" ]; then
  echo "Destination directory not found: $destination_dir"
  exit 1
fi

# Function to convert MOV files to MP4
convert_mov_to_mp4() {
  local source_file="$1"
  local destination_file="$2"
  echo "Converting $source_file"
  # Perform the conversion
  ffmpeg -i "$source_file" -c:v libx264 -c:a aac "$destination_file" -nostdin 2>/dev/null
  chown www-data:www-data "$destination_file"
}

# Initialize the converted variable outside of the loop
converted=0

# Find and convert MOV files in subdirectories
while IFS= read -r -d '' source_file; do
  # Get the relative path of the source file
  relative_path="${source_file#$source_dir/}"

  # Determine the destination file path
  destination_file="$destination_dir/${relative_path%.*}.mp4"

  # Check if the corresponding MP4 file already exists in the destination
  if [ ! -e "$destination_file" ]; then
    # Ensure the destination directory exists
    mkdir -p "$(dirname "$destination_file")"
    
    # Convert MOV to MP4 and increment the counter
    convert_mov_to_mp4 "$source_file" "$destination_file"
    converted=1
  fi
done < <(find "$source_dir" -type f -name "*.mov" -print0)

# Remove any converted mp4 files that do not have a corresponding mov file
echo "Removing any extra files"
# Clean the destination directory
while IFS= read -r -d '' mp4_file; do
  other_dir="$source_dir/${mp4_file#${destination_dir}/}"
  mov_file="${other_dir%.*}.mov"
  if [ ! -e "$mov_file" ]; then
    rm "$mp4_file"
    converted=1  # Set the variable if any files are removed
    echo "A file was removed"
    echo "$mp4_file"
  fi
done < <(find "$destination_dir" -type f -name "*.mp4" -print0)

# Check if any files were converted
if [ "$converted" -eq 1 ]; then
  echo "Files converted successfully."
  # sudo -u www-data php /var/www/html/next.msgcnx/occ files:scan --path=/walt/files/Teacher/Math/Algebra\ 1/Lesson\ Videos/
  sudo -u www-data php /var/www/html/next.msgcnx/occ files:scan --path="${destination_dir#/media/nextcloud/msgcnx}"
  chown -R www-data:www-data "$destination_dir"
  echo "Nextcloud scan complete."
else
  echo "No files were converted."
fi
exit 0