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