Setting up Nextcloud on VPS

Although Nextcloud is known as a self-hosted cloud solution, this Open-Source productivity platform offers more than just being a cloud on which you can upload files. Nextcloud offers plenty of Apps that are free, like its own messenger or integrations like Collabora Office which is a collaborative Office-Suite. Nextcloud can be used to coordinate different projects, your calendar or to host video meetings. In this tutorial I am going to show you how to install Nextcloud on your VPS. This article is meant to be helpful for everybody, not only our own Customers. 

Video Guide

Table of Contents


To install a Nextcloud you need a Linux server with root access. In this article, I’m going to deploy Nextcloud on our VPS M SSD for €8.99 / Month with Debian 11 as the Operating System. 

As a webserver, which will be used as a reverse-proxy as well, we are using Apache2. 
Moreover, it’s required to have a domain already connected to your server. 

Before we start with the actual installation, we want to make sure that our server is up to date. To do this login as root and use this command to update your server: 

apt update && apt upgrade –y 

Installation of Required Programs

The first thing we need to do is installing all required programs e.g. Apache2, PHP and a Database-Software. The installation of PHP8.0 will be explained in detail in Chapter 3. 

Let’s start by installing the required programs with this command: 

apt install apache2 unzip wget curl mariadb-client mariadb-server nano 

Installing PHP8.0

As mentioned in the chapter above we need to install PHP8.0 (or newer). This is the recommended PHP version. 

Adding Repository

Because the PHP8.0 repository isn’t included in Debian 11, we need to add it first. To do so enter these commands, command after command: 

  1. apt-get install ca-certificates apt-transport-https software-properties-common -y 
  1. echo "deb $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list 
  1. apt install gnupg gnupg2 gnupg1 -y 
  1. wget -qO - | apt-key add - 
  1. apt update && apt upgrade -y 

The repository should be installed now, so we can continue with the actual installation of PHP8.0 

Installing PHP8.0 & Necessary Modules

Installing PHP8.0 is very easy and done with just one command: 

apt install php8.0 -y 

For Nextcloud to work properly, additional PHP-Modules are required. They can be installed with this command: 

apt install libapache2-mod-php8.0 php8.0-{zip,xml,mbstring,gd,curl,imagick,intl,bcmath,gmp,cli,mysql,apcu,redis} 

Adjusting php.ini

After installing PHP and all required modules we need to adjust the php.ini which is the config of PHP. I’m going to use the nano text-editor. Open the file with this command: 

nano /etc/php/8.0/apache2/php.ini 

The following parameters need to be changed: 

  • memory_limit = 1024M 
  • upload_max_filesize = 16G 
  • post_max_size = 16G 
  • date.timezone = Europe/Berlin 

Hint: You can press [CTRL+W] to open a search-field in which you can search for these parameters (e.g. memory_limit). Hit [Enter] to jump to the exact line. With this method you don’t need to scroll through the whole config to find the values. 

After everything has been changed, save the file with [CTRL+O] and exit the editor with [CTRL+X] 

Setting up a Database

Nextcloud will store things like userinfo in a database. Therefore, we need to create one by using MariaDB. 

First login to the database software with this command: 

mysql –u root –p 

Now you will be prompted to enter your root-password 

With this command you can create the database: 

create database nextcloud; 

Now we will create a database user with this command: 

create user ‘nextcloud’@’localhost’ identified by ‘PASSWORD’; 

IMPORTANT: Please set a secure password by replacing PASSWORD in the command above. Make sure to leave the apostrophe in front and behind your password! 

Now give the database user access to the nextcloud database with this command: 

grant all privileges on nextcloud.* to ‘nextcloud’@’localhost’; 

And refresh the database with this command: 

flush privileges; 

Now the database and a database user have been created so you can exit the database software with this command: 


Downloading Nextcloud Files

Now it’s time to download the actual Nextcloud files. To do so use this command: 

cd /tmp && wget 

Because the downloaded file is a .zip-Archive we need to unzip it first with this command: 


The .zip-Archive is no longer needed so you can remove it by using this command: 


The unzipped Nextcloudfolder needs to be moved to its correct position. To do so use this command: 

mv nextcloud /var/www 

Configure Apache2

Activate Necessary Modules

In the default configuration of Apache2 some required modules to run Nextcloud are not acitved yet. We are going to active them with this command: 

a2enmod rewrite headers env dir mime 

Setting up a reverse-proxy

In order to tell Apache2 that there is a Nextcloud instance running at a specific location, we need to set up a reverse-proxy. 

To do so we are again using the nano-texteditor to create this reverse-proxy. Use this command to create the config: 

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

Now paste in the following content: 

<VirtualHost *:80> 

     ServerAdmin <YourEmail> 

     DocumentRoot /var/www/nextcloud/ 

     ServerName <Your(sub)Domain> 

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


     <Directory /var/www/nextcloud/> 

        Options +FollowSymlinks 

        AllowOverride All 

        Require all granted 

          <IfModule mod_dav.c> 

            Dav off 


        SetEnv HOME /var/www/nextcloud 

        SetEnv HTTP_HOME /var/www/nextcloud 



     ErrorLog ${APACHE_LOG_DIR}/error.log 

     CustomLog ${APACHE_LOG_DIR}/access.log combined 



IMPORTANT: You need replace <YourEmail> in the second line with a valid email address. (The brackets in front and behind your email address, “<” and “>” need to be removed!) 

Moreover, you need to replace <Your(sub)Domain> in the fourth line with your acutal (sub)domain. (Again, the brackets need to be removed!) 

After changing these two things save the file with [CTRL+O] and exit the editor with [CTRL+X] 

With the following command you can activate your config: 

a2ensite nextcloud.conf 

In order for the changes to take effect you need to restart the whole webserver with this command: 

systemctl restart apache2 

Creating a Data Folder (Optional)

By default, Nextcloud will store all uploaded data in the installation directory of your Nextcloud-instance. If you want, you can create a separate location for all uploaded data. This step is fully optional! To do so create a folder at a location of your wish, where you want your files to be uploaded with this command 

mkdir /home/data 

As you can see, I chose /home/data as the location where I want my files to be uploaded. To choose a different location, adjust the command. 

Adjusting Permissions

In order for Apache2 (the webserver) to access the Nextcloud files we need to adjust a few permissions. 

This is done by using these commands: 

chown -R www-data:www-data /var/www/nextcloud 

chmod -R 755 /var/www/nextcloud

If you followed the step described in Chapter 7, which was creating a separate folder where your uploaded files get stored, you need to change the permissions for this folder as well with this command: 

chown –R www-data:www-data /home/data 

If you’ve chosen a different location than /home/data (except the default one), adjust the path in the command above. 

Installing an SSL-Certificate (Certbot)

To make data transfer or logging in more secure, it’s recommended to install an SSL-Certificate. We are using the Certbot, which lets you generate free Let’s-Encrypt certificates which are valid for 90 days. 

More information on Certbot and how to auto-extend your certificate can be found on the official Website of Certbot. 

To install Certbot use this command: 

apt install certbot python3-certbot-apache -y 

After installing Certbot, start the program with this command: 

certbot --apache 

When you start the program for the first time, you need to agree to some licenses etc. which is intuitive. 

Now you should see a list of all your active websites (e.g.

Type in the correct number to select the site you want to install a certificate for and choose Redirect which is Option 2 in the next menu. 

Now you certificate is installed. 

Finishing Installation in Browser

All necessary programs have been installed and every setting has been adjusted. Now it’s time to finalize the installation via your browser. 

Therefor enter your (sub)domain into the URL-line of your browser. 

Now these fields will appear: 


As you can see in the screenshot you just need to fill out the form-like fields which is done in four steps: 

Step 1: Create an admin account 

Step 2 (Optional): If you chose a separate location for you your uploaded data (described in Chapter 7) you need to provide the path of this location. Otherwise leave it as it is. 

Step 3: Enter your database credentials (Chapter 4) 

For the Database user: nextcloud

Database password: PASSWORD 

Database name: nextcloud 

Because the database runs on the same server as this Nextcloud instance you can leave the localhost-part as it is. 

Step 4: Now click on Install. 

After clicking on Install this menu will appear: 

nextcloud recommended apps

Here you can choose, if you want Nextcloud to install the listed recommended apps. 

If you want so, click on Install recommended apps, otherwise click on Cancel

Now you should be greeted with this screen: 

Finished installation screen

Congratulations, now you have your own Nextcloud instance working.