Nextcloud VPS Installation and Setup Guide

Author

Reads 1K

Close Up Photo of Cables Plugged into the Server
Credit: pexels.com, Close Up Photo of Cables Plugged into the Server

Installing Nextcloud on a VPS is a straightforward process that requires some technical know-how, but don't worry, I've got you covered.

To start, you'll need to choose a VPS provider that supports Nextcloud, such as OVH or Hetzner. These providers offer a range of plans to suit different budgets and needs.

First, create a new user account on your VPS with a strong password, as this will be used to access the Nextcloud web interface. Make sure to use a secure password manager to keep track of your credentials.

Next, install the necessary dependencies, including Apache, PHP, and MariaDB, which can be done using a package manager like apt-get or yum.

Docker Configuration

To set up Nextcloud on Docker, you'll need to configure your project environment. This involves installing Docker and Docker Compose, which will allow you to manage containers that run the Nextcloud stack.

You can install Docker and Docker Compose by following the instructions in the Docker installation section. Once installed, you'll be able to use Docker Compose to configure your server environment.

Credit: youtube.com, Setting Up NextCloud on Docker w/ NGINX and Cloudflare for Remote Access!

To create a Docker Compose configuration file, you'll need to add the following content to the docker-compose.yml file:

  • version: '3' specifies the version of the Docker Compose file format being used.
  • services defines the individual containers or services that make up the application.
  • db uses the MariaDB image, serving as the database for Nextcloud, and stores data in a volume named "db".
  • redis uses the Redis image, which is a caching server.
  • app runs Nextcloud itself, uses the Nextcloud image, and exposes port 8080 on the host.
  • volumes defines named volumes used to store data persistently.

Here's a summary of the Docker Compose configuration:

To initiate the deployment of your Nextcloud instance, run the command docker-compose up in the project directory where you have the docker-compose.yml file. This will start the containers and run them in a detached mode in the background.

HTTPS and Security

Securing your Nextcloud VPS with HTTPS is a no-brainer, especially if your server is publicly accessible.

For more security, it's recommended to switch to the HTTPS protocol by adding a domain name and a TLS certificate. This is crucial for maintaining your data's confidentiality, integrity, and privacy.

To get a free SSL certificate from Let's Encrypt, you can use an Nginx proxy server. This is a great option if you don't have a domain, as you can obtain a self-signed certificate using OpenSSL.

Once you've obtained your certificate, you'll need to edit the .conf/ file by adding specific lines at the end of the file. Make sure to replace example.com with your actual domain name.

Restarting your reverse-proxy one last time will ensure that your HTTPS protocol is up and running smoothly.

Apache and PHP Configuration

Credit: youtube.com, How to Install Nextcloud Hub 21 on Ubuntu 20.04 - Apache, MySQL, and PHP Configuration

To use Nextcloud, you'll need to configure Apache and PHP. Apache requires a single configuration file, which is located at /etc/apache2/sites-available/nextcloud.conf on Debian, Ubuntu, and similar systems.

You can choose to install Nextcloud in a directory on an existing web server or in a virtual host. For a directory-based installation, you'll need to put the following configuration in your nextcloud.conf file, replacing the Directory and Alias filepaths with the correct values for your system.

For a virtual host installation, you'll need to put the following configuration in your nextcloud.conf file, replacing the ServerName, DocumentRoot, and Directory filepaths with the correct values for your system.

On Debian, Ubuntu, and similar systems, you'll need to run the following command to enable the configuration:

  1. sudo a2ensite nextcloud.conf

This will enable the Nextcloud configuration, allowing you to access it from your web browser.

PHP FPM Configuration

To set up PHP FPM, you'll need to install the necessary packages. This includes installing PHP8.0 with the command apt install php8.0 -y.

You'll also need to install additional PHP-modules for Nextcloud, which can be done with the command apt install libapache2-mod-php8.0 php8.0-{zip,xml,mbstring,gd,curl,imagick,intl,bcmath,gmp,cli,mysql,apcu,redis}.

Apache Web Server Configuration

Credit: youtube.com, Basic Apache Webserver Configuration & Virtual Hosts - Full PHP 8 Tutorial

Apache Web Server Configuration is a crucial step in setting up your server for Nextcloud. You'll need to create a configuration file for your domain, which will vary depending on your operating system.

On Debian, Ubuntu, and their derivatives, this file will be located at /etc/apache2/sites-available/nextcloud.conf. On Fedora, CentOS, RHEL, and similar systems, the configuration file will be located at /etc/httpd/conf.d/nextcloud.conf.

To use the directory-based installation, you'll need to put specific configuration code in your nextcloud.conf file, replacing the filepaths with the ones that suit your system.

To use the virtual host installation, you'll need to put different configuration code in your nextcloud.conf file, replacing ServerName, as well as the DocumentRoot and Directory filepaths with values appropriate for your system.

You should run the command `sudo a2ensite nextcloud.conf` to enable the configuration on Debian, Ubuntu, and their derivatives.

.htaccess

Nextcloud comes with its own nextcloud/.htaccess file, but php-fpm can’t read PHP settings in .htaccess, so these settings and permissions must be set in the nextcloud/.user.ini file.

You'll need to make sure the .htaccess file is writable by the HTTP user, as this is a requirement for enabling pretty URLs.

To enable pretty URLs, you'll also need to install mod_env and mod_rewrite on your webserver and run the commands sudo a2enmod env and sudo a2enmod rewrite.

Initial Setup

Credit: youtube.com, How to Set Up Nextcloud on Ubuntu 24.04 LTS

To set up your Nextcloud VPS, you'll need to install the necessary operating system, which is typically Ubuntu or CentOS.

Choose a server that meets your needs, considering factors like CPU, RAM, and storage.

For a smooth installation process, select a server with at least 2 CPU cores, 4GB of RAM, and 30GB of disk space.

Next, configure your server's network settings, including the IP address, subnet mask, gateway, and DNS server.

Make sure to update your server's package list and install the necessary dependencies before proceeding with the Nextcloud installation.

Update Server Hostname

Updating the server hostname is a crucial step in the initial setup process. It's essential to match the server hostname with your Nextcloud domain for better server management and accessibility.

You can open the hostname file in the Nano editor using the command "nano hostname". This will allow you to edit the file and update the server hostname.

Enter your domain and save the file to complete this step. If you plan to use the server's IP for access, you can skip this step.

Installation Methods

Credit: youtube.com, How to install Nextcloud on CloudPanel | VPS Tutorial

You have several options for installing Nextcloud on your VPS. One way is to use the web installer, which can be found on the Nextcloud server installation page. It's a script that checks dependencies, downloads Nextcloud, and unpacks it with the right permissions.

To use the web installer, you'll need to upload the setup-nextcloud.php file to your web space, point your browser to it, and follow the instructions. This method is easy and convenient, but it may take up to a month for major releases to become available through the web installer.

Alternatively, you can use the Snap package installer, which is a secure and sandboxed way to run applications. To install the Nextcloud Snap Package, you'll need to run a command in your terminal, which can be found in the Nextcloud Snap Package documentation.

If you're using Windows, you can install Nextcloud on a virtual machine (VM) using a free appliance built on the Univention Corporate Server (UCS). This includes user management via LDAP and optional integrations with other applications. The Nextcloud VM is maintained by T&M Hansson IT and several versions are offered.

Credit: youtube.com, How to Set Up Nextcloud on Ubuntu 24.04 LTS

Here are some installation methods for Nextcloud on a VPS:

Via Script

Installing Nextcloud via script is a convenient and easy way to get started. You can use the Nextcloud VM or NextcloudPI scripts to install Nextcloud.

The Nextcloud VM script can be downloaded and run with a single command: `sudo bash nextcloud_install_production.sh`. This script will take care of the installation for you.

The NextcloudPI script is similar, and can be downloaded and run with the command: `sudo bash install.sh`. This script will also handle the installation process.

You can choose either script based on your specific needs and preferences.

Via Snap Packages

A snap is a zip file containing an application together with its dependencies, and a description of how it should safely be run on your system.

Snaps are designed to be secure, sandboxed, containerized applications isolated from the underlying system and from other applications.

To install the Nextcloud Snap Package, run the following command in a terminal:

The snapd technology powers snaps, offering a new way to package, distribute, update, and run OS components and applications on a Linux system.

Windows (Virtual Machine)

Credit: youtube.com, How To Create a Windows Virtual Machine in Virtual Box // Windows Fundamentals // Episode 0.6

If you're using Windows, the easiest way to get Nextcloud up and running is by using a virtual machine (VM). You can install Nextcloud on a virtual machine using VirtualBox, VMWare (ESX), or KVM images.

Nextcloud GmbH maintains a free appliance built on the Univention Corporate Server (UCS) that includes user management via LDAP and can replace an existing Active Directory setup. This appliance also has optional ONLYOFFICE and Collabora Online integration.

The Nextcloud VM is maintained by T&M Hansson IT and several different versions are offered. You can install various apps like Collabora, OnlyOffice, Full Text Search, and more using the included scripts during the first setup or download them later and run them afterwards.

You can find all the currently available automated app installations on GitHub.

You'll be prompted to install recommended apps after the initial setup.

These apps provide additional functionality and features to enhance your Nextcloud instance.

You can choose to install them or skip it.

If you click to install the apps, you'll see an indication that they're being installed.

After installing the apps, you'll be automatically redirected to the default user dashboard.

Database and Files

Credit: youtube.com, Install your personal cloud with NextCloud on Debian 10 | VPS Beginner | P8

Nextcloud VPS stores user information and other data in a database, which we'll set up using MariaDB. To start, you'll need to log in to the database software with the command `mysql –u root –p`.

You'll then need to enter your root password to access the database. It's essential to set a secure password by replacing `PASSWORD` in the command `create user ‘nextcloud’@’localhost’ identified by ‘PASSWORD’;` with a strong password.

The next step is to grant all privileges on the `nextcloud` database to the newly created user with the command `grant all privileges on nextcloud.* to ‘nextcloud’@’localhost’;`. After that, refresh the database with `flush privileges;`.

Create Data Folder

Creating a separate location for uploaded data is an optional step, but it's a good idea to keep your files organized. You can use the command `mkdir /home/data` to create a separate data folder.

This command creates a new folder called `/home/data` where you can store all your uploaded files. I chose this location for the purposes of this tutorial, but you can choose a different location if you prefer.

If you decide to use a separate location, you'll need to provide the path to that location. Otherwise, you can leave it as it is.

Adjust Permissions

Credit: youtube.com, Everything You Need to Know About Windows Folder Permissions

To access your Nextcloud files, Apache2 needs specific permissions.

Use the command `chown -R www-data:www-data /var/www/nextcloud` to adjust permissions for the Nextcloud files.

This command ensures Apache2 has the necessary permissions to access the files.

You'll also need to adjust permissions for the uploaded data folder if you created it in a previous step.

Use the command `chown –R www-data:www-data /home/data` to change permissions for the folder.

If you've chosen a different location, adjust the path in the command to match your specific setup.

Database Setup

To set up a database for Nextcloud, you'll need to create a MariaDB database. This is done by logging in to the database software with the command `mysql –u root –p`, then entering your root password.

You'll create a database user with the command `create user ‘nextcloud’@’localhost’ identified by ‘PASSWORD’;`, replacing `PASSWORD` with a secure password. Don't forget to leave the apostrophe in front and behind your password for added security.

Credit: youtube.com, How To Create a Database in Microsoft Access

You can exit the database software with the command `exit;` once you've completed the setup.

To securely store sensitive information like passwords and secret keys, you'll need to create a .env file. This is done by using the command `nano .env` to create and open the file, then adding the following content:

Replace the values for these variables with secure and unique passwords. Save the file after making the changes.

The environment variables in the .env file are essential for your Nextcloud setup, providing the credentials and settings needed for Nextcloud to connect to the database.

Download Files

To download the actual Nextcloud files, you'll need to use the command `cd /tmp && wget https://download.nextcloud.com/server/releases/latest.zip`. This will fetch the latest Nextcloud files from the official server.

The downloaded file is a .zip archive, so you'll need to unzip it first using the command that follows the download.

Maximum Upload Size

To increase the maximum upload size, you'll need to modify your php.ini file, specifically the memory_limit, upload_max_filesize, and post_max_size values.

Credit: youtube.com, How to fix Importing of Large SQL files to database phpmyadmin xampp

You can use a text editor like nano to open the file, for example, nano /etc/php/8.0/apache2/php.ini.

The parameters to change are memory_limit = 1024M, upload_max_filesize = 16G, and post_max_size = 16G.

You can search for these parameters using [CTRL+W] to speed up the process.

After making these changes, remember to restart your HTTP server for the changes to take effect.

Additionally, if you're using php-fpm, you'll also need to increase the upload_max_filesize and post_max_size values in your php-fpm configuration.

Here's a summary of the parameters to change:

  • memory_limit = 1024M
  • upload_max_filesize = 16G
  • post_max_size = 16G

Don't forget to restart php-fpm and your HTTP server after making these changes.

Thomas Goodwin

Lead Writer

Thomas Goodwin is a seasoned writer with a passion for exploring the intersection of technology and business. With a keen eye for detail and a knack for simplifying complex concepts, he has established himself as a trusted voice in the tech industry. Thomas's writing portfolio spans a range of topics, including Azure Virtual Desktop and Cloud Computing Costs.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.