How to Set Up a Nextcloud Server on Ubuntu Server


Nextcloud is a powerful, open-source software suite that provides file synchronization and sharing capabilities. In this comprehensive guide, we will walk you through the process of setting up a Nextcloud server on Ubuntu Server. We will also explore the importance of patch management and how can simplify this crucial task for your Linux servers.


Before you start, ensure you have the following:

  • An Ubuntu Server (24.04 or later).
  • A user with sudo privileges.
  • Basic knowledge of command-line operations.
  • A domain name (optional but recommended for HTTPS).

Step 1: Update Your Server

Start by updating your server’s package list and installing available updates. This ensures that you have the latest security patches and software updates.

sudo apt update
sudo apt upgrade -y

Step 2: Install Apache, MySQL, and PHP (LAMP Stack)

Nextcloud requires a web server, a database server, and PHP. We'll use Apache, MySQL, and PHP, commonly referred to as the LAMP stack.

Install Apache

sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2

Install MySQL

sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysql

Secure MySQL

sudo mysql_secure_installation

Follow the prompts to secure your MySQL installation.

Install PHP

sudo apt install php libapache2-mod-php php-mysql php-gd php-json php-curl php-mbstring php-intl php-imagick php-xml php-zip -y

Step 3: Download and Configure Nextcloud

Download the latest version of Nextcloud from the official website.

cd /var/www/
sudo wget
sudo unzip
sudo mv nextcloud /var/www/html/
sudo chown -R www-data:www-data /var/www/html/nextcloud/
sudo chmod -R 755 /var/www/html/nextcloud/

Step 4: Configure Apache for Nextcloud

Create a new Apache configuration file for Nextcloud.

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

Add the following configuration:

<VirtualHost *:80>
  DocumentRoot /var/www/html/nextcloud
  ServerName your_domain_or_IP

  <Directory /var/www/html/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off

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


Enable the new configuration and necessary Apache modules.

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

Step 5: Set Up SSL with Let's Encrypt

It is highly recommended to secure your Nextcloud server with HTTPS. We can use Let's Encrypt to obtain a free SSL certificate.

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache

Follow the prompts to obtain and install the SSL certificate.

Step 6: Complete the Installation via Web Interface

Open your web browser and navigate to your server’s domain name or IP address to complete the installation through the Nextcloud web interface.

You will be prompted to create an admin account and enter the database details:

  • Database user: nextclouduser
  • Database name: nextcloud
  • Database password: the password you set earlier
  • Database host: localhost

Step 7: Enable Additional Nextcloud Security and Optimization

To ensure your Nextcloud server is secure and optimized, you can enable additional security settings and performance improvements.

Configure Memory Caching

Edit the Nextcloud configuration file to enable memory caching.

sudo nano /var/www/html/nextcloud/config/config.php

Add the following lines:

'memcache.local' => '\\OC\\Memcache\\APCu',

Set Up Cron Jobs

Set up a cron job to handle background tasks.

sudo crontab -u www-data -e

Add the following line:

*/15 * * * * php -f /var/www/html/nextcloud/cron.php

The Importance of Patch Management

Keeping your server up-to-date with the latest security patches is crucial for maintaining a secure and stable environment. Patching helps protect against vulnerabilities that can be exploited by attackers.

Common Patching Scenarios

  • Fixing security vulnerabilities
  • Improving system performance
  • Adding new features or functionality
  • Resolving bugs and other issues

How Simplifies Patch Management is a patch management platform that makes it easy to keep your Linux servers up-to-date. With, you can automate the process of patching, ensuring that your servers are always secure and running smoothly.

Key Features of

  • Automated patch management
  • Detailed patch reports
  • Customizable patch policies
  • Easy integration with existing infrastructure


Setting up a Nextcloud server on Ubuntu Server provides you with a powerful tool for file synchronization and sharing. By following the steps outlined in this guide, you can ensure a secure and efficient installation. Additionally, leveraging a patch management solution like can help maintain the security and stability of your server, simplifying the process of keeping your system up-to-date.

For more information on patch management and to get started with, visit