EN · $

Install and Optimize Nextcloud on a VPS

Learn how to install Nextcloud on your VPS and configure it for maximum performance. Step-by-step guide for a fast and secure cloud solution.

Why Nextcloud on a VPS?

Nextcloud is a powerful open-source cloud solution that gives you full control over your data. A VPS (Virtual Private Server) provides the ideal environment to run Nextcloud with maximum performance. You benefit from dedicated resources, full root access, and the flexibility to customize the configuration to your needs. With our VPS servers, you are guaranteed the necessary performance for your cloud.

Prerequisites for Installation

Before you start, make sure you have the following:

  • A running VPS with Linux (e.g., Ubuntu 22.04 LTS)
  • Root access via SSH
  • A domain pointing to your VPS (optional but recommended)
  • Basic knowledge of the command line

Step 1: Update System and Install Dependencies

Connect via SSH to your VPS and run the following commands:

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

This installs the Apache web server, MariaDB database, and all required PHP modules.

Step 2: Set Up Database for Nextcloud

Log in to MariaDB and create a database and user:

sudo mysql -u root
CREATE DATABASE nextcloud;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Note down the database name, user, and password – you will need them later.

Step 3: Download and Extract Nextcloud

Download the latest Nextcloud version and extract it into the web directory:

cd /var/www
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo chown -R www-data:www-data nextcloud
sudo rm latest.zip

Step 4: Configure Apache

Create a virtual host configuration for Nextcloud:

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

Add the following content (replace your-domain.com with your domain or IP):

<VirtualHost *:80>
    ServerAdmin admin@your-domain.com
    DocumentRoot /var/www/nextcloud
    ServerName your-domain.com

    <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the site and required modules:

sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime
sudo systemctl restart apache2

Step 5: Complete Installation via Browser

Open your browser and navigate to the IP address or domain of your VPS. You will be redirected to the Nextcloud installation page. Enter the following:

  • Admin account: Create a username and a secure password
  • Data directory: Leave the default path or choose your own
  • Database: Select "MySQL/MariaDB" and enter the database details created earlier

Click "Install" and wait for the process to complete.

Basic Configuration for Maximum Performance

Enable PHP OPcache

Edit the PHP configuration:

sudo nano /etc/php/8.1/apache2/php.ini

Set the following values:

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1

Use Redis for Caching

Install Redis and the PHP module:

sudo apt install redis-server php8.1-redis -y
sudo systemctl enable redis-server

Add the following lines to the Nextcloud configuration file /var/www/nextcloud/config/config.php:

'memcache.local' => '\OC\Memcache\Redis',
'redis' => array(
    'host' => 'localhost',
    'port' => 6379,
),

Optimize Database

Run the command sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices regularly to improve database performance.

Additional Tips for Maximum Performance

  • Use HTTP/2 for faster load times
  • Enable GZip compression in Apache
  • Use a CDN for static files
  • Set up regular maintenance tasks via cron job

With these settings, you get the most out of your VPS. If you don't have a VPS yet, check out our VPS servers – they provide the ideal foundation for Nextcloud. For further assistance, we are happy to help.