EN · $

Setting up Nextcloud on a VPS: SSL & Database Optimization

Learn how to install Nextcloud on your VPS, automatically manage SSL, and optimize database performance for maximum speed.

Why Nextcloud on a VPS?

Nextcloud offers you a private cloud solution for files, calendars, and contacts. A VPS from dezhost gives you full control and the resources you need for optimal performance. In this article, we show you how to set up Nextcloud with automatic SSL certificate management and optimized database performance.

Prerequisites

You need a VPS with Ubuntu 22.04 or newer, as well as root access. Make sure your server has enough RAM and CPU cores – for Nextcloud we recommend at least 2 GB RAM. A VPS from dezhost easily meets these requirements.

Step 1: Basic Installation of Nextcloud

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

  • Update the system: sudo apt update && sudo apt upgrade -y
  • Install the LAMP stack: sudo apt install apache2 mariadb-server php php-mysql libapache2-mod-php php-gd php-json php-curl php-mbstring php-intl php-imagick php-xml php-zip php-apcu -y
  • Download and extract Nextcloud: cd /var/www/html && sudo wget https://download.nextcloud.com/server/releases/latest.zip && sudo unzip latest.zip
  • Set up the database: Create a database and a user for Nextcloud.

Step 2: Automatic SSL Certificate Management with Let's Encrypt

Use Certbot to obtain an SSL certificate and automatically renew it:

  • Install Certbot: sudo apt install certbot python3-certbot-apache -y
  • Run Certbot: sudo certbot --apache -d yourdomain.com
  • Certbot automatically sets up HTTP to HTTPS redirection and renews the certificate automatically.

Step 3: Optimizing Database Performance

For maximum speed, optimize MariaDB/MySQL:

  • Open the configuration file: sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
  • Adjust the following parameters:
    • innodb_buffer_pool_size = 1G (for 2 GB RAM)
    • innodb_log_file_size = 256M
    • query_cache_size = 64M
    • max_connections = 150
  • Restart the service: sudo systemctl restart mariadb

Step 4: Nextcloud Configuration for Speed

Edit the Nextcloud configuration file config.php:

  • Enable memory caching: 'memcache.local' => '\OC\Memcache\APCu',
  • Set the database index: 'dbindex' => true,
  • Configure cron job execution: Set the cron mode to 'cron' => 'cron', and set up a system-wide cron job.

Summary

With these steps, you have installed Nextcloud on your VPS, automated SSL certificates, and optimized database performance. Your private cloud now runs securely and quickly. If you don't have a VPS yet, check out our VPS offers – they are ideal for Nextcloud and many other applications.