How to install NextCloud 13 on Debian 9

How to install NextCloud 13 on Debian 9

We’ll show you, how to install NextCloud 13 on Debian 9. Nextcloud is an open-source software suite that allows users to store their data such as files, contacts, calendars, news feed, TODO lists and much more, on their personal servers. It is using standard protocols such as webdavm, carddav and caldav. It also provides client applications so users can easily manage and synchronize their data among Linux, MacOS, Windows platforms and smart phones, which makes Nextcloud a great free alternative to proprietary cloud services such as Dropbox, Google Drive, iCloud, etc…

In this tutorial we will install and configure Nextcloud 13 on a Debian 9 VPS, with Apache web server, PHP and MariaDB.

Requirements

Before we start with the installation there are several requirements:

  • SSH ‘root’ access to your server.
  • MySQL or MariaDB 5.5+; PostgreSQL version 9 or 10;
  • PHP version 7.0, 7.1 or 7.2.
  • Apache version 2.4 with mod_php or Nginx (php-fpm) web server

Login via SSH and update your system

Login to your Debian 9 VPS via SSH as user root

ssh root@IP_Address -p Port_Number

and make sure that all installed packages are up to date by running the following command

apt update && apt upgrade

Install Apache web server

As mentioned in the requirements, a web server is required to run Nextcloud. Run the following command to install Apache on your VPS

apt install apache2

Once installed, start Apache and enable it to start at server boot

systemctl start apache2
systemctl enable apache2

Install PHP

Install PHP and some PHP modules required by NextCloud

apt install php7.0 libapache2-mod-php7.0 php7.0-common php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php7.0-imagick php7.0-xml php7.0-zip

Install MariaDB and create a database

Next, we will install MariaDB server using the following command

apt -y install mariadb-server

Start the database server and enable it to start upon server boot

systemctl enable mariadb
systemctl start mariadb

Run the mysql_secure_installation post-installation script to harden the security of your MariaDB server and set a ‘root’ password. You can use the following options

mysql_secure_installation

Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Now, login to the MariaDB server as user root and create a new user and database for Nextcloud

mysql -u root -p

MariaDB [(none)]> CREATE DATABASE nextcloud;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud_user'@'localhost' IDENTIFIED BY 'PASSWORD';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;

Don’t forget to replace ‘PASSWORD’ with an actual strong password. Combination of letters and numbers and minimum 10 characters long is recommended.

Download and install Nextcloud
Go go Nextcloud’s official website and download Nextcloud 13 to your Debian 9 VPS. Currently latest stable version is 13.0.1

wget https://download.nextcloud.com/server/releases/nextcloud-13.0.1.zip

Extract the downloaded ZIP archive in a directory Apache has access to, and change the ownership of the nextcloud directory to the web server user

unzip nextcloud-13.0.1.zip -d /var/www/html/
chown -R www-data:www-data /var/www/html/nextcloud/

Once all Nextcloud prerequisites are fulfilled, we can complete installation using the on-screen installation wizard or through the command line. We will complete the installation through the command line. Change the current working directory

cd /var/www/html/nextcloud

and execute the following command as the web server user

sudo -u www-data php occ  maintenance:install --database "mysql" --database-name "nextcloud"  --database-user "nextcloud_user" --database-pass "PASSWORD" --admin-user "admin" --admin-pass "PASSWORD"

Use the database information we created above and set a strong password for the Nextcloud ‘admin’ user.

If the installation is successfull you will get the following output

Nextcloud was successfully installed

Edit the config/config.php file and add domain.com as a trusted domain

nano config/config.php

 'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'domain.com',
  ),

Create Apache Virtual Host

If you want to be able to access Nextcloud with a domain name, you will have to create a new virtual host. Create the following file

nano /etc/apache2/sites-available/domain.com.conf

<VirtualHost *:80>

ServerAdmin admin@domain.com
DocumentRoot /var/www/html/nextcloud
ServerName domain.com
ServerAlias www.domain.com

Alias /nextcloud “/var/www/html/nextcloud/”

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

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

SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
</Directory>

ErrorLog /var/log/apache2/nextcloud-error_log
CustomLog /var/log/apache2/nextcloud-access_log common

</VirtualHost>

Save the file and enable the newly created virtual host

a2ensite domain.com.conf

It is also recommended to enable the mod_headers, mod_env, mod_dir and mod_mime Apache modules

a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime

To activate the new configuration, you need to run the following command

systemctl reload apache2

With this step the Nextcloud 13 installation is completed. You can now visit http://domain.com and login to your Nextcloud instance using the credentials used in the insallation command above.


Of course, you don’t have to Install NextCloud 13 on Debian 9, if you use one of our NextClould Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on How To Install NextCloud 13 on Debian 9, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

8 thoughts on “How to install NextCloud 13 on Debian 9”

  1. Your virtualhost config seems to have been chewed up by a filter. Everything that might pass as an html tag ( directory and virtualhost tags ) has been stripped. Otherwise great tutorial, by the way!

    Reply
  2. Hi Team,

    I am new with linux and Nextcloud. Before I proceed with above steps, I found that Apache web server, PHP, Maria DB in my website, Do I need to update it or re-install? I want to install Nextcloud and want see nextcloud in sub-domain of my domain e.g. www.test.com/nextcloud.

    Please help me?

    Reply
    • Edit the Apache configuration file (/etc/apache2/sites-available/domain.com.conf) and locate these lines:

      ServerName domain.com
      ServerAlias www.domain.com

      Replace ‘domain.com’ and ‘www.domain.com’ with your actual domain name and subdomain name.

      Reply
  3. Your command: sudo -u www-data php occ maintenance:install –database “mysql” –database-name “nextcloud” –database-user “nextcloud_user” –database-pass “PASSWORD” –admin-user “admin” –admin-pass “PASSWORD”
    Who is “admin” (and its password) in this case? Do you create there an ‘admin’ for the whole NextCloud-Database, or ist there mean the admin of whole MySQL-DB-Access (mysql-root)?

    Reply

Leave a Comment