Quick Start: Netcloud installation

After a couple of issues with the nextcloud snap on Ubuntu 18.04, what follows is a quick0start recipe I used to get nextcloud up and running.

Issues:

I encountered the following issues with the Ubuntu 18.04 nextcloud snap, that I couldn't quickly and easily finf a way to address. I really like snaps and I hope these will eventually be addressed.

  • Changing the 'datadirectory' outside of the snap was problematic.
    In the case of a VirtualBox Shared folder, even once correctly set up (and there was quite a lot of magic for that ...);
  • the SMB PHP module wasn't installed and the 'simple' instructions  in the documentation didn't work (for me).

also

  • I wanted a little bit more control without having to learn the in's-and-out's of snaps (at this point  in time).

Preparation

  • You will need a good password for the 'root' user off the database.
  • You will need a good password for the 'nextclouduser', owner of the nextcloud database (MariaDB used here);
    These will need to be entered a number of times throughout the install.
  • Download the latest nextcloud server version:

$ wget https://download.nextcloud.com/server/releases/nextcloud-15.0.4.zip
$ unzip nextcloud-15.0.4.zip

  • Install Maria DB from the MariaDB repositories:
# apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
# sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.3/ubuntu bionic main'
# apt -y install mariadb-server
# systemctl status mariadb
mariadb.service - MariaDB 10.3.12 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset:
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2019-02-12 00:17:03 UTC; 1min 1s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 16589 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 32 (limit: 1110)
   CGroup: /system.slice/mariadb.service
           └─16589 /usr/sbin/mysqld
[...deleted]

# mysql -V
mysql  Ver 15.1 Distrib 10.3.12-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
[...deleted]
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

  • Signup for the security rss feed!

Create the nextcloud database:

# mysql -p

MariaDB [(none)]> CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
MariaDB [(none)]> GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY '<nextclouduser's password here>';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Install apache:

# apt -y install apache2

Install php (including the smb modules):

  • In addition to the usual ubuntu repositories:

deb http://archive.ubuntu.com/ubuntu bionic universe main
deb http://archive.ubuntu.com/ubuntu bionic-security main
deb http://archive.ubuntu.com/ubuntu bionic-updates main

  • To meet package dependencies the following repositories were added

deb http://archive.ubuntu.com/ubuntu bionic multiverse restricted
deb http://archive.ubuntu.com/ubuntu bionic-security multiverse restricted universe
deb http://archive.ubuntu.com/ubuntu bionic-updates  multiverse restricted universe

  • then ...

# apt -y install php7.2 php7.2-gd php7.2-json php7.2-mysql php7.2-curl php7.2-mbstring php7.2-intl php7.2-imagick php7.2-xml php7.2-zip libapache2-mod-php7.2

Install nextcloud:

 

cp -r ~/nextcloud /var/www
chown -R www-data.www-data /var/www/nextcloud

Create the apache configuration:

# cat > /etc/apache2/sites-available
Alias / "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
  Options +FollowSymlinks
  AllowOverride All

 <IfModule mod_dav.c>
  Dav off
 </IfModule>

 SetEnv HOME /var/www/nextcloud
 SetEnv HTTP_HOME /var/www/nextcloud

</Directory>

Load necessary/suggested apache modules:

# a2enmod rewrite
# a2enmod headers
# a2enmod env
# a2enmod dir
# a2enmod mime

Enable the site:

# a2ensite nextcloud