<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.itcollege.ee/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ebarrier</id>
	<title>ICO wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.itcollege.ee/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ebarrier"/>
	<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php/Special:Contributions/Ebarrier"/>
	<updated>2026-05-07T15:20:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119905</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119905"/>
		<updated>2017-04-07T07:22:14Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install Nextcloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use Nextcloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_cacheMissing.png|border|900px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis====&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis PHP module====&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119899</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119899"/>
		<updated>2017-04-07T06:58:02Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_cacheMissing.png|border|900px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis====&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis PHP module====&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119898</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119898"/>
		<updated>2017-04-07T06:56:45Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_cacheMissing.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis====&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis PHP module====&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_cacheMissing.png&amp;diff=119897</id>
		<title>File:Nextcloud cacheMissing.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_cacheMissing.png&amp;diff=119897"/>
		<updated>2017-04-07T06:40:32Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119859</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119859"/>
		<updated>2017-04-05T14:42:06Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable caching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis====&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis PHP module====&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119857</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119857"/>
		<updated>2017-04-05T13:40:40Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis====&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis PHP module====&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119856</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119856"/>
		<updated>2017-04-05T08:43:26Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis====&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Install Redis PHP module====&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119855</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119855"/>
		<updated>2017-04-05T08:42:19Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119854</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119854"/>
		<updated>2017-04-05T08:38:27Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Improve Nextcloud */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But doing using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following lines in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119853</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119853"/>
		<updated>2017-04-05T08:37:25Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But doing using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally add the following line to Nextcloud&#039;s config file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&#039;memcache.locking&#039; =&amp;gt; &#039;\OC\Memcache\Redis&#039;,&lt;br /&gt;
 &#039;redis&#039; =&amp;gt; array(&lt;br /&gt;
      &#039;host&#039; =&amp;gt; &#039;localhost&#039;,&lt;br /&gt;
      &#039;port&#039; =&amp;gt; 6379,&lt;br /&gt;
       ),&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119852</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119852"/>
		<updated>2017-04-05T08:32:36Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its [https://pecl.php.net/package/redis PECL repository].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud this tutorial] installs Redis PHP 7 module directly from the module&#039;s git repository&amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;. But doing using this method does not install the latest version of the module that can be found on [https://pecl.php.net/package/redis PECL repository].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later), the Pear PHP extension repository tools:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev php-pear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install the nodule from PECL repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pecl install redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enable the module and restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpenmod redis&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check the version of the module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ php --ri redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119851</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119851"/>
		<updated>2017-04-05T08:08:57Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its git repository &amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later) and git (if not already installed):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;SAVED URL: https://community.openenergymonitor.org/t/php-redis-3-1-1/3124/11&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We clone the git repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/phpredis/phpredis.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Move the directory &#039;&#039;phpredis&#039;&#039; to &#039;&#039;/etc/&#039;&#039; and we &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv phpredis/ /etc/&lt;br /&gt;
$ cd /etc/phpredis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install PHPRedis ([https://github.com/phpredis/phpredis#installation as per the installation instructions]):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpize&lt;br /&gt;
$ ./configure&lt;br /&gt;
$ make &lt;br /&gt;
$ make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/7.0/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119850</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119850"/>
		<updated>2017-04-05T07:43:16Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from [http://packages.ubuntu.com/xenial Ubuntu Xenial (16.04) repository] is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its git repository &amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later) and git (if not already installed):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We clone the git repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/phpredis/phpredis.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Move the directory &#039;&#039;phpredis&#039;&#039; to &#039;&#039;/etc/&#039;&#039; and we &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv phpredis/ /etc/&lt;br /&gt;
$ cd /etc/phpredis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install PHPRedis ([https://github.com/phpredis/phpredis#installation as per the installation instructions]):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpize&lt;br /&gt;
$ ./configure&lt;br /&gt;
$ make &lt;br /&gt;
$ make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119836</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119836"/>
		<updated>2017-04-04T13:17:16Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from Ubuntu Xenial (16.04) repository is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its git repository &amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later) and git (if not already installed):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We clone the git repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/phpredis/phpredis.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Move the directory &#039;&#039;phpredis&#039;&#039; to &#039;&#039;/etc/&#039;&#039; and we &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv phpredis/ /etc/&lt;br /&gt;
$ cd /etc/phpredis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install PHPRedis ([https://github.com/phpredis/phpredis#installation as per the installation instructions]):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpize&lt;br /&gt;
$ ./configure&lt;br /&gt;
$ make &lt;br /&gt;
$ make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the php.ini file which is situated at /etc/php/7.0/apache2/php.ini.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119835</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119835"/>
		<updated>2017-04-04T13:15:21Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from Ubuntu Xenial (16.04) repository is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;. PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its git repository &amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later) and git (if not already installed):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We clone the git repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/phpredis/phpredis.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Move the directory &#039;&#039;phpredis&#039;&#039; to &#039;&#039;/etc/&#039;&#039; and we &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv phpredis/ /etc/&lt;br /&gt;
$ cd /etc/phpredis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install PHPRedis ([https://github.com/phpredis/phpredis#installation as per the installation instructions]):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpize&lt;br /&gt;
$ ./configure&lt;br /&gt;
$ make &lt;br /&gt;
$ make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the web server to use the module, add it to php.ini:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ touch /etc/php/mods-available/redis.ini&lt;br /&gt;
$ echo &#039;extension=redis.so&#039; &amp;gt; /etc/php/mods-available/redis.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; the above can be achieved by adding the line &amp;quot;extension=redis.so&amp;quot; directly into the &#039;&#039;php.ini&#039;&#039; file which is situated at &#039;&#039;/etc/php/7.0/apache2/php.ini&#039;&#039;).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119834</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119834"/>
		<updated>2017-04-04T13:08:39Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from Ubuntu Xenial (16.04) repository is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;. PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its git repository &amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later) and git (if not already installed):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We clone the git repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/phpredis/phpredis.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Move the directory &#039;&#039;phpredis&#039;&#039; to &#039;&#039;/etc/&#039;&#039; and we &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv phpredis/ /etc/&lt;br /&gt;
$ cd /etc/phpredis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install PHPRedis ([https://github.com/phpredis/phpredis#installation as per the installation instructions]):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpize&lt;br /&gt;
$ ./configure&lt;br /&gt;
$ make &lt;br /&gt;
$ make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119833</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119833"/>
		<updated>2017-04-04T13:07:05Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from Ubuntu Xenial (16.04) repository is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;. PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its git repository &amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later) and git (if not already installed):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We clone the git repository:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ git clone https://github.com/phpredis/phpredis.git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We move the directory &#039;&#039;phpredis&#039;&#039; to &#039;&#039;/etc/&#039;&#039; and we &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; into it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv phpredis/ /etc/&lt;br /&gt;
$ cd /etc/phpredis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ phpize&lt;br /&gt;
$ ./configure&lt;br /&gt;
$ make &lt;br /&gt;
$ make install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119832</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119832"/>
		<updated>2017-04-04T12:52:29Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module. This module provides an API to PHP to communicate with a Redis server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from Ubuntu Xenial (16.04) repository is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;. PHP 7 needs the Redis PHP module 3.1.x or higher. We use the latest stable version of the module directly from its git repository &amp;lt;ref&amp;gt;[https://github.com/phpredis/phpredis] PHPRedis module official Git repository&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
First install the PHP development tools (&amp;quot;phpize&amp;quot; which will be used later) and git (if not already installed):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php7.0-dev git&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119831</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119831"/>
		<updated>2017-04-04T09:49:09Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Enable transactional file locking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and unpack it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we install the Redis PHP 7 module.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note:&#039;&#039;&#039; The &amp;lt;code&amp;gt;php-redis&amp;lt;/code&amp;gt; package from Ubuntu Xenial (16.04) repository is of version 2.2.x which only works with PHP 5.6.x &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html#additional-redis-installation-help] Nextcloud&#039;s official documentation - Additional Redis Installation Help&amp;lt;/ref&amp;gt;&#039;&#039;. We use the latest stable version of the module.&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119830</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119830"/>
		<updated>2017-04-04T09:25:59Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt-get update&lt;br /&gt;
$ apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and decompress it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
$ tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cd Redis&lt;br /&gt;
$ make&lt;br /&gt;
$ make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all the tests are successful, install Redis:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ make install&lt;br /&gt;
$ cd utils/&lt;br /&gt;
$ ./install_server.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal will ask questions, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; for default settings:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Please select the redis port for this instance: [6379] Selecting default: 6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis config file name [/etc/redis/6379.conf] &lt;br /&gt;
Selected default - /etc/redis/6379.conf&lt;br /&gt;
&lt;br /&gt;
Please select the redis log file name [/var/log/redis_6379.log] &lt;br /&gt;
Selected default - /var/log/redis_6379.log&lt;br /&gt;
&lt;br /&gt;
Please select the data directory for this instance [/var/lib/redis/6379] &lt;br /&gt;
Selected default - /var/lib/redis/6379&lt;br /&gt;
&lt;br /&gt;
Please select the redis executable path [/usr/local/bin/redis-server]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Selected config:&lt;br /&gt;
Port : 6379&lt;br /&gt;
Config file : /etc/redis/6379.conf&lt;br /&gt;
Log file : /var/log/redis_6379.log&lt;br /&gt;
Data dir : /var/lib/redis/6379&lt;br /&gt;
Executable : /usr/local/bin/redis-server&lt;br /&gt;
Cli Executable : /usr/local/bin/redis-cli&lt;br /&gt;
&lt;br /&gt;
Is this ok? Then press ENTER to go on or Ctrl-C to abort.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Redis is now install. See its version:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ /usr/local/bin/redis-server -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119829</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119829"/>
		<updated>2017-04-04T09:07:47Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Caching improves performance by storing data, code, and other objects in memory.&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable transactional file locking===&lt;br /&gt;
&lt;br /&gt;
The more users access Nextcloud, the more it is possible they read, modify, save the same files. When this happens, data error/corruption can occur.&lt;br /&gt;
&lt;br /&gt;
[https://docs.nextcloud.com/server/11/admin_manual/configuration_files/files_locking_transactional.html Nextcloud official documentation] recommends to use [https://redis.io Redis] transactional file locking system. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;quot;Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.&amp;quot;&#039;&#039; &amp;lt;ref&amp;gt;[https://redis.io/] Redis&#039;s official website&amp;lt;/ref&amp;gt;. In Nextcloud, Redis prevents simultaneous file saving, but not simultaneous file reading and modification. It also does not warn users that they are accessing the same file.&lt;br /&gt;
&lt;br /&gt;
The commands below mostly rely on the [https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ following tutorial.]&lt;br /&gt;
&lt;br /&gt;
First install the packages we will need to install Redis (GNU C and C++ compilers, etc.):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get install build-essential&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the latest released version of Redis&#039; archive and decompress it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://download.redis.io/releases/redis-stable.tar.gz&lt;br /&gt;
tar xzf redis-stable.tar.gz&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Change its folder name from &#039;&#039;redis-stable&#039;&#039; to just &#039;&#039;redis&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mv redis-stable redis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile Redis and test it:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd Redis&lt;br /&gt;
make&lt;br /&gt;
make test   ## This will take time&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119828</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119828"/>
		<updated>2017-04-04T08:06:14Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Improve Nextcloud==&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable caching===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Caching improves performance by storing data, code, and other objects in memory.&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119827</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119827"/>
		<updated>2017-04-04T08:03:55Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizard&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
===Improve Nextcloud===&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
====Enable strict transport security====&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Enable caching====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Caching improves performance by storing data, code, and other objects in memory.&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
On a clean Nextcloud installation the following admin screen is visible.&lt;br /&gt;
&lt;br /&gt;
IMAGE cacheMissing&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
We use APCu &amp;lt;ref&amp;gt;[http://php.net/manual/en/book.apcu.php] PHP.net official documentation - APCu cache system&amp;lt;/ref&amp;gt; as the cache system and Redis &amp;lt;ref&amp;gt;[https://redis.io] Redis official documentation&amp;lt;/ref&amp;gt; as the file locking system.&lt;br /&gt;
&lt;br /&gt;
First install APCu:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation] installs APCu with the package name &amp;lt;code&amp;gt;php7.0-apcu&amp;lt;/code&amp;gt; which has a different name for Ubuntu 16.04.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apt install php-apcu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart the web server:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
service apache2 restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add the following line in the &amp;lt;code&amp;gt;config.php&amp;lt;/code&amp;gt; file of your Nextcloud installation (&#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039; in our example):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;memcache.local&#039; =&amp;gt; &#039;\OC\Memcache\APCu&#039;,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After refreshing Nextcloud page, check that the cache warning message disappeared.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119826</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119826"/>
		<updated>2017-04-04T07:38:05Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
===Improve Nextcloud===&lt;br /&gt;
&lt;br /&gt;
Now that Nextcloud is up and running, we can improve its settings.&lt;br /&gt;
&lt;br /&gt;
The following sections are recommended to implement although they may be ignored.&lt;br /&gt;
&lt;br /&gt;
====Enable strict transport security====&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Enable caching====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Caching improves performance by storing data, code, and other objects in memory.&#039;&#039;&amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html] Nextcloud&#039;s official documentation - Enable and configure memory caching&amp;lt;/ref&amp;gt; Basically the service will run faster with caching.&lt;br /&gt;
&lt;br /&gt;
Different caching solutions and configurations can be used depending on type of server implementation. We only show how to install and configure caching for a small organization architecture with a single Nextcloud server. For more architecture examples, see [https://docs.nextcloud.com/server/11/admin_manual/configuration_server/caching_configuration.html Nextcloud&#039;s official documentation].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119779</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119779"/>
		<updated>2017-03-29T06:46:30Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119778</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119778"/>
		<updated>2017-03-29T06:35:53Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Preliminary notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119777</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119777"/>
		<updated>2017-03-29T06:23:36Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Preliminary notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119653</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119653"/>
		<updated>2017-03-27T10:51:20Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Set up Nextcloud from graphical installation wizard */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed and accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119652</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119652"/>
		<updated>2017-03-27T10:50:43Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up Nextcloud from graphical installation wizard===&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable strict transport security===&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119651</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119651"/>
		<updated>2017-03-27T10:49:39Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Enable strict transport security==&lt;br /&gt;
Nextcloud&#039;s official documentation strongly recommends to enable strict transport security for HTTP protocol &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/configuration_server/harden_server.html?highlight=security#enable-http-strict-transport-security] Nextcloud&#039;s official documentation - Enable HTTP Strict Transport Security&amp;lt;/ref&amp;gt; to avoid man-in-the-middle-attacks.&lt;br /&gt;
&lt;br /&gt;
To do so, the Apache HTTPS virtual host should contain the following settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
  ServerName [yourServerName]&lt;br /&gt;
    &amp;lt;IfModule mod_headers.c&amp;gt;&lt;br /&gt;
      Header always set Strict-Transport-Security &amp;quot;max-age=15552000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example configuration will make all subdomains only accessible via HTTPS. If you have subdomains not accessible via HTTPS, remove &amp;lt;code&amp;gt;includeSubdomains;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119650</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119650"/>
		<updated>2017-03-27T10:36:08Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* What is the final state this tutorial reaches? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled.&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119649</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119649"/>
		<updated>2017-03-27T10:26:46Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Preliminary notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119648</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119648"/>
		<updated>2017-03-27T10:25:28Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Preliminary notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the same)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119647</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119647"/>
		<updated>2017-03-27T10:24:25Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119646</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119646"/>
		<updated>2017-03-27T10:23:48Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Troubleshoot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119645</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119645"/>
		<updated>2017-03-27T10:23:16Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119644</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119644"/>
		<updated>2017-03-27T10:22:14Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_MariaDBRunning.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_siteEnabled.png|border|700px|center]]&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_installWebWizard.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_webSetup.png|border|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_pageAfterinstall.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_webSetup.png&amp;diff=119643</id>
		<title>File:Nextcloud webSetup.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_webSetup.png&amp;diff=119643"/>
		<updated>2017-03-27T10:20:42Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_siteEnabled.png&amp;diff=119642</id>
		<title>File:Nextcloud siteEnabled.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_siteEnabled.png&amp;diff=119642"/>
		<updated>2017-03-27T10:19:00Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_pageAfterinstall.png&amp;diff=119641</id>
		<title>File:Nextcloud pageAfterinstall.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_pageAfterinstall.png&amp;diff=119641"/>
		<updated>2017-03-27T10:17:52Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_MariaDBRunning.png&amp;diff=119640</id>
		<title>File:Nextcloud MariaDBRunning.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_MariaDBRunning.png&amp;diff=119640"/>
		<updated>2017-03-27T10:16:57Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_installWebWizard.png&amp;diff=119639</id>
		<title>File:Nextcloud installWebWizard.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_installWebWizard.png&amp;diff=119639"/>
		<updated>2017-03-27T10:14:34Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119638</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119638"/>
		<updated>2017-03-27T10:14:05Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Troubleshoot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE MariaDBRunning&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
IMAGE siteEnabled&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
IMAGE webSetup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
IMAGE pageAfterinstall&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_binlogFormat.png&amp;diff=119636</id>
		<title>File:Nextcloud binlogFormat.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_binlogFormat.png&amp;diff=119636"/>
		<updated>2017-03-27T10:12:48Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119635</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119635"/>
		<updated>2017-03-27T10:10:24Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Troubleshoot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE MariaDBRunning&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
IMAGE siteEnabled&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
IMAGE webSetup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
IMAGE pageAfterinstall&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_binlogFormat.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119634</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119634"/>
		<updated>2017-03-27T10:09:25Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Troubleshoot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE MariaDBRunning&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
IMAGE siteEnabled&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
IMAGE webSetup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
IMAGE pageAfterinstall&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud__binlogFormat.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_trustedDomains.pnglogFormat.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_trustedDomains.png&amp;diff=119633</id>
		<title>File:Nextcloud trustedDomains.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_trustedDomains.png&amp;diff=119633"/>
		<updated>2017-03-27T10:08:43Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119632</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119632"/>
		<updated>2017-03-27T10:07:21Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: /* Database access denied */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE MariaDBRunning&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
IMAGE siteEnabled&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
IMAGE webSetup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
IMAGE pageAfterinstall&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[FILE:Nextcloud_accessDenied.png|border|300px|center]]&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE binlogFormat&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE trustedDomains&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=File:Nextcloud_accessDenied.png&amp;diff=119631</id>
		<title>File:Nextcloud accessDenied.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=File:Nextcloud_accessDenied.png&amp;diff=119631"/>
		<updated>2017-03-27T10:03:01Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119630</id>
		<title>Install NextCloud on Ubuntu Server 16.04</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Install_NextCloud_on_Ubuntu_Server_16.04&amp;diff=119630"/>
		<updated>2017-03-27T09:51:24Z</updated>

		<summary type="html">&lt;p&gt;Ebarrier: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Author: Etienne Barrier&lt;br /&gt;
&lt;br /&gt;
==Preliminary notes==&lt;br /&gt;
This tutorial shows how to install NextCloud on Ubuntu 16.04 LTS Server, using MariaDB (as for database) and Apache 2 (as for web server).&lt;br /&gt;
&lt;br /&gt;
This tutorial does NOT show:&lt;br /&gt;
* how to install/configure databases other than MariaDB (although MySQL can be considered the sane)&lt;br /&gt;
* how to install/configure web servers other than Apache2 (for example Nginx)&lt;br /&gt;
* how to use NextCloud&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered in terminal with Bash shell start with a dollar sign &amp;quot;$&amp;quot;. Terminal&#039;s outputs do not start with dollar sign.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ echo I Love You  # This is a command&lt;br /&gt;
I Love You         # This is an output&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All commands in this tutorial are made as root. You must be root or be able to use &amp;quot;sudo&amp;quot; command to install and configure Nextcloud.&lt;br /&gt;
&lt;br /&gt;
Commands that must be entered for MariaDB start with greater-than sign &amp;quot;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tools&#039; versions used in this tutorial:&lt;br /&gt;
* Nextcloud (version: 11.0.1)&lt;br /&gt;
* Ubuntu 16.04.1 LTS (Xenial)&lt;br /&gt;
* MariaDB (version: 10.1.21)&lt;br /&gt;
* Apache 2 (version: 2.4.18)&lt;br /&gt;
* Php (version 7.0)&lt;br /&gt;
&lt;br /&gt;
The version of Nextcloud used (version 11) is referred as “Nextcloud” across the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This tutorial is based on the following tutorials:&lt;br /&gt;
*[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html Official NextCloud documentation]&lt;br /&gt;
*[https://downloads.mariadb.org/mariadb/repositories/ MariaDB official downdload and installation page]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For any comments, please write to ebarrier {at] itcollege [dot) ee.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is the final state this tutorial reaches?==&lt;br /&gt;
This tutorial&#039;s objective is to have Nextcloud installed on a Ubuntu server using the aforementioned tools.&lt;br /&gt;
&lt;br /&gt;
The installation of tools will be done from the command line.&lt;br /&gt;
&lt;br /&gt;
The installation of Nextcloud will be done from command line and web interface.&lt;br /&gt;
&lt;br /&gt;
Nextcloud will be accessible from the main page of the webserver and https protocol will be enabled and forced.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==MariaDB==&lt;br /&gt;
&lt;br /&gt;
MariaDB is a database server that was forked from MySQL. It is free and open source.&lt;br /&gt;
&lt;br /&gt;
===Install MariaDB===&lt;br /&gt;
We [https://downloads.mariadb.org/mariadb/repositories install MariaDB] directly from its package repository.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-16-04-lts-server] Nextcloud&#039;s official documentation - Linux installation&amp;lt;/ref&amp;gt; installs MariaDB with the command &amp;lt;code&amp;gt;apt install mariadb-server&amp;lt;/code&amp;gt;. Experience showed that this package does not work properly and leads to troubles later. Therefore the present instructions for installing MariaDB differ from Nextcloud&#039;s.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Import the key to the package repository and add it to the package source list (added in /etc/apt/source.list).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install software-properties-common&lt;br /&gt;
$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8&lt;br /&gt;
$ add-apt-repository &#039;deb [arch=amd64] http://ftp.eenet.ee/pub/mariadb/repo/10.1/ubuntu xenial main&#039;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then update the packages list and install mariadb.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt update&lt;br /&gt;
$ apt install mariadb-server&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;When the wizard asks whether to set up a root password, it is important to set it and to remember it!&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once installation finishes, check that MariaDB is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl status mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE MariaDBRunning&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===MariaDB secure installation===&lt;br /&gt;
&lt;br /&gt;
MariaDB secure installation &amp;lt;ref&amp;gt;[https://mariadb.com/kb/en/mariadb/mysql_secure_installation] MariaDB secure installation&amp;lt;/ref&amp;gt; is a script that enhances the security of MariaDB. &lt;br /&gt;
It is highly recommended to run it.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql_secure_installation&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first question of the wizard is to enter the root password that was chosen in the previous step. Enter it.&lt;br /&gt;
&lt;br /&gt;
The second question asks whether we want to change the root password or not. &lt;br /&gt;
&lt;br /&gt;
For all next questions, press &#039;&#039;Enter&#039;&#039; (&amp;quot;Yes&amp;quot; by default).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create user and database for Nextcloud===&lt;br /&gt;
Create a dedicated user and database that will be used by Nextcloud during its installation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: Nextcloud&#039;s official documentation &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#database-choice-label] Nextcloud&#039;s official documentation - Database set up from graphical wizad&amp;lt;/ref&amp;gt; uses MariaDB&#039;s root password during its installation to set up the database (see below). In the present tutorial, a Nextcloud&#039;s dedicated user is created to avoid to enter the root password later (for security reasons).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First enter MariaDB as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mysql -u root -p&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When prompted, enter the root password (we told you to remember it!).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;: database statements (commands) do not need to be capitalize. But the semi-colon in the end is important, they are part of the statement.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create the database (define your own database name; &amp;quot;nextcloud&amp;quot; in our example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; CREATE DATABASE nextcloud;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then create a user with its password (define both your own; &amp;quot;arold&amp;quot; and &amp;quot;salakala&amp;quot; in our example respectively) and grant all rights to it to the newly created database (&amp;quot;nextcloud&amp;quot; in our example).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Save the changes and exit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Apache and PHP==&lt;br /&gt;
Install the other tools Nextcloud will need (Apache2 web server, PHP 7 and its modules):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ apt install apache2 libapache2-mod-php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Make sure the following Apache modules are enabled:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod rewrite&lt;br /&gt;
$ a2enmod headers&lt;br /&gt;
$ a2enmod env&lt;br /&gt;
$ a2enmod dir&lt;br /&gt;
$ a2enmod mime&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Already enable the SSL module and its default site configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ a2enmod ssl&lt;br /&gt;
$ a2ensite default-ssl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Restart Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 restart&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nextcloud==&lt;br /&gt;
&lt;br /&gt;
===Donwload Nextcloud===&lt;br /&gt;
Download Nextcloud&#039;s archive use wget:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check from [https://nextcloud.com/install/#instructions-server Nextcloud&#039;s installation page] the exact link&#039;s target to use.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-11.0.1.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Check Nextcloud&#039;s archive integrity===&lt;br /&gt;
Check that the archive&#039;s integrity by comparing its checksum.&lt;br /&gt;
&lt;br /&gt;
Download the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ wget https://download.nextcloud.com/server/releases/nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check that the downloaded archive matches the checksum file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ sha256sum -c nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;.sha256 &amp;lt; nextcloud-&#039;&#039;version&#039;&#039;.&#039;&#039;file-extension&#039;&#039;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it matches, the terminal will display &amp;lt;code&amp;gt;OK&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Install Nextcloud===&lt;br /&gt;
Extract the archive depending on its extension: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ tar -xjf nextcloud-x.y.z.tar.bz2&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ unzip nextcloud-x.y.z.zip&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will extract one single directory called &amp;quot;nextcloud&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This extracted directory will be used by the web server. &lt;br /&gt;
&lt;br /&gt;
As for Apache, we can move it to &#039;&#039;/var/www&#039;&#039; (document root of Apache).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ mv nextcloud /var/www&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the file &#039;&#039;/etc/apache2/sites-available/nextcloud.conf&#039;&#039; with the following content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;&lt;br /&gt;
Alias /nextcloud &amp;quot;/var/www/nextcloud/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Directory /var/www/nextcloud/&amp;gt;&lt;br /&gt;
  Options +FollowSymlinks&lt;br /&gt;
  AllowOverride All&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;IfModule mod_dav.c&amp;gt;&lt;br /&gt;
    Dav off&lt;br /&gt;
  &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  SetEnv HOME /var/www/nextcloud&lt;br /&gt;
  SetEnv HTTP_HOME /var/www/nextcloud&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This configuration makes the Nextcloud web application available at the address &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then enable this configuration file: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;apache&amp;quot;&amp;gt;$ a2ensite nextcloud&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reload Apache to apply all these changes: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ service apache2 reload&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As screenshot below shows, Nextcloud is visible in a browser at the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, but Apache needs to access its directory.&lt;br /&gt;
&lt;br /&gt;
IMAGE siteEnabled&lt;br /&gt;
&lt;br /&gt;
To fix this, make Apache the owner of Nextcloud&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ chown -R www-data:www-data /var/www/nextcloud/&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the address &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud the following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set strong directory permissions===&lt;br /&gt;
To make the application more secure, Nextcloud provides a script which sets strict directory permissions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This step must be done once Nextcloud has been installed otherwise some permissions will not be as recommended &amp;lt;ref&amp;gt;[https://docs.nextcloud.com/server/11/admin_manual/installation/installation_wizard.html#strong-perms-label] Nextcloud strong directory permissions&amp;lt;/ref&amp;gt;.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a temporary file that will hold the script to execute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ nano /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy and paste the following code into the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ocpath=&#039;/var/www/nextcloud&#039;&lt;br /&gt;
htuser=&#039;www-data&#039;&lt;br /&gt;
htgroup=&#039;www-data&#039;&lt;br /&gt;
rootuser=&#039;root&#039;&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;Creating possible missing Directories\n&amp;quot;&lt;br /&gt;
mkdir -p $ocpath/data&lt;br /&gt;
mkdir -p $ocpath/assets&lt;br /&gt;
mkdir -p $ocpath/updater&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod Files and Directories\n&amp;quot;&lt;br /&gt;
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640&lt;br /&gt;
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750&lt;br /&gt;
chmod 755 ${ocpath}&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chown Directories\n&amp;quot;&lt;br /&gt;
chown -R ${rootuser}:${htgroup} ${ocpath}/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/apps/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/assets/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/config/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/data/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/themes/&lt;br /&gt;
chown -R ${htuser}:${htgroup} ${ocpath}/updater/&lt;br /&gt;
&lt;br /&gt;
chmod +x ${ocpath}/occ&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;chmod/chown .htaccess\n&amp;quot;&lt;br /&gt;
if [ -f ${ocpath}/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
if [ -f ${ocpath}/data/.htaccess ]&lt;br /&gt;
 then&lt;br /&gt;
  chmod 0644 ${ocpath}/data/.htaccess&lt;br /&gt;
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ bash /tmp/nextcloud.sh&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The terminal should output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Creating possible missing Directories&lt;br /&gt;
chmod Files and Directories&lt;br /&gt;
chown Directories&lt;br /&gt;
chmod/chown .htaccess&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up Nextcloud from graphical installation wizard==&lt;br /&gt;
This set up will finish to install Nextcloud from your browser.&lt;br /&gt;
&lt;br /&gt;
From your browser, go to &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud. The following screen should appear:&lt;br /&gt;
&lt;br /&gt;
IMAGE installWebWizard&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Create an admin account&#039;&#039;&amp;quot; section asks to create the credentials that will be used to manage Nextcloud&#039;s administrator web interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Data folder&#039;&#039;&amp;quot; section shows the path of the directory where the Nextcloud&#039;s content (files uploaded by users) will be stored. It is recommended to store the data in a folder sitting outside the web server&#039;s path for safety reasons. But in case of Apache, the default folder (&#039;&#039;var/www/nextcloud/data&#039;&#039;) is considered secure with the strict directory permissions [[#Set_strong_directory_permissions|set up previously]].&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;&#039;&#039;Configure the database&#039;&#039;&amp;quot; section asks for the settings of the database to use. Enter the values you chose when creating the database in [[#Create_user_and_database_for_Nextcloud|a previous section]].&lt;br /&gt;
&lt;br /&gt;
Once filled-in, the screen looks like this (enter your own values):&lt;br /&gt;
&lt;br /&gt;
IMAGE webSetup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally Nextcloud is installed accessible&lt;br /&gt;
&lt;br /&gt;
IMAGE pageAfterinstall&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Troubleshoot==&lt;br /&gt;
&lt;br /&gt;
While on &amp;lt;nowiki&amp;gt;http://&amp;lt;/nowiki&amp;gt;&#039;&#039;yourDomainOrIp&#039;&#039;/nextcloud, there can be errors. Here the most probable ones with their fix.&lt;br /&gt;
&lt;br /&gt;
===Database access denied===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Error while trying to create admin user:&lt;br /&gt;
Failed to connect to the database:&lt;br /&gt;
An exception occured in driver:&lt;br /&gt;
SQLSTATE[HY000][1045] Access denied for user &#039;arold&#039;@&#039;localhost&#039; (using password:YES)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE accessDenied&lt;br /&gt;
&lt;br /&gt;
The solution is to re-enter the commands to grant all privileges to the user for the database we created [[#Create_user_and_database_for_Nextcloud|earlier]]. &#039;&#039;The values &amp;quot;arold&amp;quot; (user name) and &amp;quot;salakala&amp;quot; (user password) are just for example. Choose your own.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&amp;gt; GRANT ALL ON nextcloud.* to &#039;arold&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;salakala&#039;;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do not forget to apply the changes before exiting.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&amp;gt; exit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Binlog_format error===&lt;br /&gt;
If the following message appears:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
An unhandled exception has been thrown: exception ‘PDOException’ with message &#039;SQLSTATE[HY000]: &lt;br /&gt;
General error: 1665 Cannot execute statement: impossible to write to binary log &lt;br /&gt;
since BINLOG_FORMAT = STATEMENT and at least one tableuses a storage engine limited to row-based logging. &lt;br /&gt;
InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE binlogFormat&lt;br /&gt;
&lt;br /&gt;
Uncomment and change the line &#039;&#039;BINLOG_FORMAT = ROW&#039;&#039; in the database configuration file (&#039;&#039;/etc/mysql/my.cnf&#039;&#039;) and set its value to &#039;&#039;BINLOG_FORMAT = MIXED&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Then restart the MariaDB: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ systemctl restart mariadb&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Trusted domains===&lt;br /&gt;
For security reasons, Nextcloud have a (white)list of URLs that are allowed to access it.&lt;br /&gt;
&lt;br /&gt;
If the URL used is not whitelisted, the following message will appear:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
You are accessing the server from an untrusted domain.&lt;br /&gt;
Please contact you administrator. If you are an administrator of this instance, configure the &amp;quot;trusted-domains&amp;quot; setting in config/config.php. An example configuration is provided in config/config.sample.php.&lt;br /&gt;
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE trustedDomains&lt;br /&gt;
&lt;br /&gt;
The solution is to click the buttong &amp;quot;Add [domain] as trusted domain&amp;quot; or to add it manually in the file &#039;&#039;/var/www/nextcloud/config/config.php&#039;&#039;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;4-5&amp;quot;&amp;gt;&lt;br /&gt;
&#039;trusted_domains&#039; =&amp;gt;&lt;br /&gt;
  array (&lt;br /&gt;
    0 =&amp;gt; &#039;192.168.0.29&#039;,&lt;br /&gt;
    1 =&amp;gt; &#039;cloud.example.com&#039;,&lt;br /&gt;
    2 =&amp;gt; &#039;192.168.0.33&#039;,&lt;br /&gt;
  ),&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://certbot.eff.org/#ubuntuxenial-apache Install free SSL certificate for domains with Certbot (Letsencrypt.org)]&lt;br /&gt;
* In case of big troubles with MariaDB, [http://askubuntu.com/questions/703123/mariadb-10-1-server-wont-start-after-update how to uninstall it completely (purge)]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist|30em}}&lt;/div&gt;</summary>
		<author><name>Ebarrier</name></author>
	</entry>
</feed>