How to Install Nextcloud on Ubuntu Server

There are a lot of things Windows Server does well. However, coming off of the NAS environment, there are a lot of things that it doesn’t. One of these is a simple method for web access to various files and folders, along with the ability to share them via user login or simple url. Until recently, there had been only one real player in this space, OwnCloud. I had fiddled with the product for some time, but features were slow to show and it just didn’t work the way I had been hoping it would.

When I had finished the last server build, I had been looking for a way to simply address the needs that QNAP had been fulfilling for me with ease. With MyQNAPCloud I could easily share files or folders without issue. While on the hunt for the latest release of OwnCloud, I hit Google and just tried something. I tried “OwnCloud vs” and let the magic of Google happen. That is how I found Nextcloud.

While I won’t get into how Nextcloud came to be, I will tell you that there are a ton of similarities between the two products. When you do some research, it will become clear why that is. However, that is neither here nor there, the product is attractive, seamless, but a major pain in the … to get running. As usual, the best things in life are on linux. With that in mind, I created a Hyper-V hosting Ubuntu Server LTS 16.04 and started my journey.

Much of what I detail out here will be under the assumption that you have a CLEAN Ubuntu LAMP server up and running. For me, Hyper-V was a quick and logical start, but that doesn’t limit you to anything. Feel free to run VirtualBox, VMWare, or dedicated hardware.

Considerations

Before you build out your virtual machine for this install, there are some considerations to make. For instance, you need to plan for the amount of space that your VM will occupy. For me, it is easy, all my folders reside on another server, so a 100GB virtual hard drive is overkill. I have seen some “paid” for preconfigured VMs running around in 500GB and 1TB flavors.

System Requirements

(Taken Directly from Nextcloud.com)

Memory

Memory requirements for running an Nextcloud server are greatly variable, depending on the numbers of users and files, and volume of server activity. Nextcloud needs a minimum of 128MB RAM, and we recommend a minimum of 512MB.

Recommended Setup for Running Nextcloud
For best performance, stability, support, and full functionality we recommend:

  • Red Hat Enterprise Linux 7 / Ubuntu 16.04 LTS
  • MySQL/MariaDB
  • PHP 7.0 +
  • Apache 2.4 with mod_php

Supported Platforms

  • Server: Linux (Debian 7, SUSE Linux Enterprise Server 11 SP3 & 12, Red Hat Enterprise Linux/CentOS 6.5 and 7 (7 is 64-bit only), Ubuntu 14.04 LTS, 16.04 LTS)
  • Web server: Apache 2 (mod_php, php-fpm) or Nginx (php-fpm)
  • Databases: MySQL/MariaDB 5.5+; PostgreSQL; Oracle 11g (currently only possible if you contact us <https://nextcloud.com/enterprise> as part of a subscription)
  • PHP 5.6 + required
  • Hypervisors: Hyper-V, VMware ESX, Xen, KVM
  • Desktop: Windows XP SP3 (EoL Q2 2015), Windows 7+, Mac OS X 10.7+ (64-bit only), Linux (CentOS 6.5, 7 (7 is 64-bit only), Ubuntu 12.04 LTS, 14.04 LTS, 14.10, Fedora 20, 21, openSUSE 12.3, 13, Debian 7 & 8).
  • Mobile apps: iOS 7+, Android 4+
  • Web browser: IE11+, Microsoft Edge, Firefox 14+, Chrome 18+, Safari 7+

Database Requirements for MySQL / MariaDB

The following is currently required if you’re running Nextcloud together with a MySQL / MariaDB database:

  • Disabled or BINLOG_FORMAT = MIXED configured Binary Logging (See: MySQL / MariaDB with Binary Logging Enabled)
  • InnoDB storage engine (MyISAM is not supported)
  • “READ COMMITED” transaction isolation level (See: Database “READ COMMITED” transaction isolation level)

Installing Ubuntu Server

Download: https://www.ubuntu.com/download/server/thank-you?version=16.04.1&architecture=amd64

Walking through the standard install, for the most part, is a series of next and enter clicks. There isn’t much excitement. After you get past choosing your language, Install Ubuntu Server.

The installation will guide you through a series of pretty standard questions:

Once the additional components are completed, it is time to pick your system’s hostname. If you don’t know, a hostname is a label assigned to a device for identification. I named mine “nextcloud”, but while creating this tutorial, I left the default in place.

The username and password you choose are completely up to you. Make them something you will not forget!

When asked the next few questions, the easiest way to go is with the defaults, that is until you get to Paritition Disks.

Partition disks, Yes. Full Size, Yes. Write Changes, Yes. Proxy, continue.

 

Choosing whether Ubuntu will install updates automatically is up to you, this is something you can change.

Software selection is the start. Here, the easiest way to proceed is to select LAMP, SAMBA, OpenSSH.

If you selected the previous recommendations, you will eventually be asked for a MySQL password. Pick a password that is easy to remember but hard enough to guess.

Install GRUB

As your installation finishes, it is important to take note that you have a basic install of Ubuntu Server. This is not a hardened version nor are there any security considerations made. Security is not something to take lightly and there are plenty of threads on many great sites that can get you going.

Installing Nextcloud

Once your system has rebooted, the fun work of installing Nextcloud can begin. I would like to start off by saying, I am not the author of this entire process. While some of it is mine, I have also collected the information from various websites and collected them into a single tutorial.

Log into your system with the username and password you provided during your install.

When you first log into your server, you will be dropped in your user’s home directory. The path for this will be, by default, /home/username

There are a few modules that Nextcloud will need

sudo apt-get install libxml2-dev php-zip php-dom php-xmlwriter php-xmlreader php-gd php-curl php-mbstring

Let’s start by fetching the latest build, available at the time of this tutorial, of Nextcloud

wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.tar.bz2

Now, we need mod_rewrite

a2enmod rewrite

Restart Apache

sudo service apache2 reload

Once the download has completed, let’s untar.

tar -vxjf nextcloud-11.0.1.tar.bz2

Move the folder to /var/www. When you first run “sudo” you will have to re-enter your password.

sudo mv nextcloud /var/www

If you plan on connecting Nextcloud to your Windows Server, like I am, you will have to make sure you have Samba installed and configured. In my efforts, I have found that SMB2 is required for Nextcloud to function properly.

sudo apt-get install smbclient php-smbclient

Change the configuration of samba for SMB2

sudo nano /etc/samba/smb.conf

When the file opens, you will have to add teh following lines under [global]

max protocol = SMB2
client max protocol = SMB2

To exit the editor CTRL-X and click Y to confirm, then Enter to save

Create the apache configuration file

sudo nano /etc/apache2/sites-available/nextcloud.conf

Paste the following into the file and save.

Alias /nextcloud "/var/www/nextcloud/"

Alias /nextcloud “/var/www/nextcloud/”
Options +FollowSymlinks
AllowOverride All
Dav off

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

 

To exit the editor CTRL-X and click Y to confirm, then Enter to save

Create a symbolic link for apache

sudo ln -s /etc/apache2/sites-available/nextcloud.conf /etc/apache2/sites-enabled/nextcloud.conf

Enable the apache modules required for Nextcloud.

sudo a2enmod headers

restart apache

sudo service apache2 reload

Create the DB for Nextcloud

sudo mysql -u root -p

When prompted, enter the password your created for your database during the install

Create the user for your database. In the example below, I chose nextcloud as the password for the user nextclouduser. DO NOT USE THAT PASSWORD! Create your own password.

CREATE USER nextclouduser@localhost IDENTIFIED BY 'nextcloud';

Grant all privileges for that user

GRANT ALL PRIVILEGES ON nextcloud.* TO nextclouduser@localhost;

Exit

Secure and provide write abilities for Nextcloud (nextcloud in the example below is the username I chose during install)

sudo nano /home/nextcloud/grantperm.sh

Paste the following

#!/bin/bash
ocpath='/var/www/nextcloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'

printf “Creating possible missing Directories\n”
mkdir -p $ocpath/data
mkdir -p $ocpath/updater

printf “chmod Files and Directories\n”
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750

printf “chown Directories\n”
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/

chmod +x ${ocpath}/occ

printf “chmod/chown .htaccess\n”
if [ -f ${ocpath}/.htaccess ] then
chmod 0644 ${ocpath}/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ] then
chmod 0644 ${ocpath}/data/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

To exit the editor CTRL-X and click Y to confirm, then Enter to save

Grant execution privileges

sudo chmod +x grantperm.sh

Run the script

sudo ./grantperm.sh

Open a browser, navigate to the IP address or hostname of the server you just completed to finalize the Nextcloud install

http://ipaddress/nextcloud

If you don’t know the IP address of the machine, you can use ifconfig to find it

ifconfig

Fill in the required fields and enjoy. If you followed this tutorial to the letter, pick a username and password for nextcloud admin

Database user: nextclouduser
Password: nextcloud
Database: nextcloud
Database host: localhost

There are more things to do, for instance, there are a ton of security concerns to consider. There are also caching recommendations. I also highly recommend that you consider using https for your server.

Caching: https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html
Security: https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html
Backups: https://docs.nextcloud.com/server/11/admin_manual/maintenance/backup.html

About Joe D

I have always had a passion for everything computing. In early 2000, I decided to take my passion to the web. Thus, C.O.D. was born. Through the years we have made many great friends at C.O.D. and hope to continue our journey for years to come.

Check Also

How to Remove a Physical Disk from Windows Storage Spaces using PowerShell

Having my latest server build running on the Windows Server platform, there are a number of things that I have found to become a bit more difficult than I am used to. Not only have I switched to Windows as the platform, I am using Storage Spaces. This in itself is a departure from my comfort zone and has presented some scenarios that I wasn't quite prepared for. Like trying to remove a disk that Windows, for some reason, wants to keep.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.