8.2.7 Deployment NextCloud on server

The Host NextCloud Banner

NextCloud is a modern open-source alternative to Google Drive, Dropbox, and Yandex.Disk for your private or corporate cloud. It allows you to store, synchronize, and share files from any device.

Server Preparation

Requirements

  • Virtual or dedicated server (VPS/VDS) with Ubuntu 22.04 or 24.04 LTS;
  • CPU: 2+ cores;
  • RAM: from 4 GB (8 GB recommended for teams);
  • SSD disk (capacity according to your storage needs);
  • root access (or sudo);
  • Domain name (required for proper HTTPS operation).

Installing and Configuring Components

Before installing NextCloud, install the required packages:

sudo apt update && sudo apt upgrade -y
sudo apt install apache2 mysql-server libapache2-mod-php \
php php-mysql php-xml php-gd php-curl php-zip php-mbstring \
php-intl php-bcmath php-gmp php-imagick php-redis redis-server unzip curl -y

update upgrade sys Install dep

To enable HTTPS support, it is recommended to install certbot. You can find detailed installation instructions in our general guide.

Configuring MySQL for NextCloud

  1. Log in to MySQL:
mysql -u root -p
  1. Run the following commands:
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Explanation: Database name, username, and password should be strong and unique—used only for NextCloud.

Downloading and Installing NextCloud

  1. Go to your web app directory:
cd /var/www/
  1. Download and extract the NextCloud package:
sudo curl -o nextcloud.zip https://download.nextcloud.com/server/releases/latest.zip
sudo unzip nextcloud.zip
sudo chown -R www-data:www-data nextcloud
sudo chmod -R 755 nextcloud

Why this is important: The www-data permissions are mandatory for Apache operation and secure file uploads.

Apache Configuration for NextCloud

  1. Create the site config file:
sudo nano /etc/apache2/sites-available/nextcloud.conf
  1. Paste the following:
<VirtualHost *:80>
  ServerName cloud.example.com

  DocumentRoot /var/www/nextcloud/
  <Directory /var/www/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
  CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>

— where cloud.example.com is your domain (or IP for testing).

  1. Enable the site and required modules:
sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime ssl
sudo systemctl reload apache2

a2ensite

  1. Make sure that in the Apache config for the nextcloud directory, AllowOverride All is set.

Setting up HTTPS

  1. Get a free SSL certificate:
sudo certbot --apache -d cloud.example.com

certbotinstall

  1. Follow the instructions in the terminal and wait for the Congratulations! message.

certbotapacheactivate

Important! Never use NextCloud without HTTPS—your files can be intercepted!

Completing NextCloud Installation

  1. Open your browser and go to your domain (for example, http://cloud.example.com).

  2. Fill in the fields:

    • Administrator username and password (you are creating a new user)
    • Database: MySQL/MariaDB
    • Username: nextcloud
    • Password: (your STRONG_PASSWORD)
    • Database name: nextcloud
    • Database server: localhost

webinterfacesetup

  1. Click “Install”. After logging in, configure apps, integrations, upload limits, etc.

If all previous steps were completed correctly, you should see the following page:

webinterface nextcloud


Typical issues and quick solutions
Issue Cause Solution
PHP module not found Required PHP module not installed/activated sudo apt install php-module_name, restart Apache
502/504 Gateway Timeout Not enough RAM or low PHP limits Increase RAM, adjust php.ini (memory_limit, max_execution_time)
No write permission Wrong permissions or owner for NextCloud folder sudo chown -R www-data:www-data /var/www/nextcloud
Can’t connect to MySQL Wrong credentials/service not running Check login/password, DB name, status: sudo systemctl status mysql
SSL/certificate error Certificate, domain, or DNS problem Run certbot again, check DNS records and domain correctness