Home // How to install Nextcloud on Ubuntu 20.04
1 5 mins read
| Published on: October 1, 2022 | Last updated on: May 20, 2024

Nextcloud is a great choice if you want to create your own file sharing and syncing platform. Let me walk you through the simple steps needed to install Nextcloud on Ubuntu.

Nextcloud is an open-source application server that allows you to host your own file sharing and synchronization solution. It lets you store all of your files, documents, and contacts in one centralized location. Unlike Dropbox, Google Drive, OneDrive, and other closed-source cloud storage options, Nextcloud is free for everyone to use.

Moreover, users will be able to access their files from any computer by logging onto the Nextcloud server, similar to Dropbox. Nextcloud’s server software was specifically developed to run on Linux distributions, making it simple to set up, even for the most inexperienced Linux user. Let’s not waste any more time and get started.

With Nextcloud, you can share files with other people and keep all of your devices in sync. Additionally, you can create extra accounts for family and friends, which is another significant benefit.

In this guide, we’ll show you how to install Nextcloud on Ubuntu and configure it for optimal performance.


Before proceeding with the installation, ensure that your Ubuntu system meets the following prerequisites:

  • A fresh installation of Ubuntu (this guide is based on Ubuntu 22.04 LTS)
  • Root or sudo access for installing packages and configuring the system

Step 1: Install the Apache Web Server

Nextcloud is a web-based application, so you’ll need to set up a web server before you can use it. In this guide, we’ll be using the Apache web server.

sudo apt install -y apache2 apache2-utils

After Apache has been installed, make sure it’s running:

sudo systemctl status apache2

The output should indicate that the Apache web server is active and running.

Step 2: Install PHP 8.1 for Nextcloud

Since Nextcloud is written in PHP, you’ll need to install PHP and its required modules. Follow these steps to install nextcloud on ubuntu, PHP 8.1 and the necessary modules for Nextcloud.

Enabling the PHP Repository

Ondřej Surý, a contributor to the Debian project, maintains a repository with several PHP distributions. To add this repository, run the following commands:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

After enabling the PPA, you can proceed with installing PHP 8.1.

Installing PHP as an Apache Module

Installing PHP as an Apache module is straightforward:

sudo apt update
sudo apt install php libapache2-mod-php php8.1 libapache2-mod-php8.1

Once the packages are installed, restart Apache to load the PHP module:

sudo systemctl restart apache2

Setting Up PHP-FPM for Apache

PHP-FPM is a FastCGI process manager for PHP. Install the necessary packages with the following command:

sudo apt update
sudo apt install php8.1-fpm php-fpm libapache2-mod-fcgid

By default, PHP-FPM is not enabled in Apache. To enable it, run:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.1-fpm

Restart Apache to activate the changes:

sudo systemctl restart apache2

Installing PHP Extensions

PHP extensions are built-in libraries that extend PHP’s core functionality. You can easily install extensions using apt:

sudo apt install php8.1-{mysql,redis,imagick,common,gd,json,curl,zip,xml,mbstring,bz2,intl,bcmath,gmp}

This command installs the required extensions for Nextcloud, including MySQL, Redis, ImageMagick, and others.

Reload Apache for the changes to take effect:

sudo systemctl reload apache2

And reload the PHP-FPM service:

sudo service php8.1-fpm restart

Verify your PHP version:

php -v

Step 3: Set Up the MariaDB Database Server

To install Nextcloud on Ubuntu while ensuring optimal data storage capabilities, this comprehensive guide will walk you through setting up the recommended MariaDB database solution.

sudo apt install mariadb-server

Once the MariaDB server is up and running, you’ll need to secure it by changing the root password:

sudo mysql_secure_installation

Follow the prompts to set a strong root password and configure other security options.

Establish a New Nextcloud Database and User

Use the root user to connect to MariaDB:

sudo mysql -u root -p

Then, create a new database for Nextcloud:

CREATE DATABASE nextclouddb;

Next, create a new user and grant privileges to the Nextcloud database:

GRANT ALL ON nextclouddb.* TO nextclouduser@'localhost' IDENTIFIED BY 'your-password';

Replace nextclouduser and your-password with your desired username and password.

Reload privileges and exit:


Verify that the new user has access to the database:

mysql -u nextclouduser -p

Step 4: Obtain and Install Nextcloud

After configuring the database, you can proceed with the installation of Nextcloud on Ubuntu. The Nextcloud software package is distributed as a compressed file. Before starting, visit the official Nextcloud download page to ensure you are downloading the latest version.

Assuming the latest version is “28.0.3” (please check for the latest version before proceeding), use the following command to download Nextcloud and its SHA-256 checksum for verification:

wget https://download.nextcloud.com/server/releases/nextcloud-28.0.3.zip
wget https://download.nextcloud.com/server/releases/nextcloud-28.0.3.zip.sha256

Verify the download’s integrity:

sha256sum -c nextcloud-28.0.3.zip.sha256

If the output indicates the file is OK, proceed with the installation by extracting the archive into your web directory, creating a data directory for user data, and setting the appropriate permissions:

sudo unzip nextcloud-28.0.3.zip -d /var/www/html/
sudo mkdir /var/www/html/nextcloud/data
sudo chown -R www-data:www-data /var/www/html/nextcloud/

Step 5: Configure Apache and Secure Nextcloud with SSL

To configure Apache, create or edit the virtual host file for Nextcloud located at /etc/apache2/sites-available/nextcloud.conf with the following configuration:

<VirtualHost *:80>
    DocumentRoot /var/www/html/nextcloud/
    ServerName your.server.com

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

        <IfModule mod_dav.c>
            Dav off

Replace your.server.com with your actual domain name.

To secure your Nextcloud installation with an SSL certificate, you can use Let’s Encrypt, a free and automated certificate authority:

sudo apt update
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d your.server.com

Follow the prompts to complete the setup. Certbot will modify your Apache configuration to use the SSL certificate and set up automatic renewal.

Verify the automatic renewal process by running a dry-run:

sudo certbot renew --dry-run

Step 6: Configure Nextcloud

With Nextcloud installed and secured, you can now proceed with the configuration:

  1. Open your web browser and navigate to http://server-ip/nextcloud/.
  2. Fill in the Username and Password to create your admin account.
  3. Set the Data folder. You can find the data stored in /var/www/html/nextcloud/data.
  4. Connect using the login credentials (nextclouduser), password (your-password), and database name (nextclouddb) you created in Step 3.
  5. Click “Finish Setup” to complete the Nextcloud installation on Ubuntu.

Nextcloud will immediately grant you system administrator privileges and log you in, making it that simple to set up your personal cloud storage service.


By following this comprehensive guide, you’ve successfully installed Nextcloud on Ubuntu, giving you a self-hosted file sharing and syncing platform with full control over your data. Nextcloud offers a robust set of features, including file sharing, calendars, contacts, and more, all accessible from any device.

Remember to keep your Nextcloud instance updated with the latest security patches and explore the various apps and plugins available to enhance your experience further.

Happy Nextclouding!

Frequently Asked Questions

Q: Can I use a different web server instead of Apache?

Yes, Nextcloud supports other web servers like Nginx. While the installation process may differ slightly, the overall steps for setting up the database, PHP, and Nextcloud itself would remain similar.

Q: Do I need to install all the PHP extensions listed in the guide?

The guide covers installing a comprehensive set of PHP extensions required for Nextcloud’s core functionality and various apps. However, if you don’t plan on using certain features (like image manipulation or specific database drivers), you can skip installing those extensions.

Q: How can I update Nextcloud to the latest version?

Nextcloud provides regular updates to introduce new features, security fixes, and bug fixes. You can update Nextcloud through the web interface by navigating to the “Updates” section in the admin area. It’s recommended to back up your data and configuration before performing an update.

Q: Can I use Nextcloud for team collaboration and file sharing?

Absolutely! Nextcloud offers robust collaboration features, including file sharing, shared calendars, and more. You can create user accounts for your team members and manage permissions and access controls to facilitate secure collaboration.

It’s essential to have a reliable backup strategy in place for your Nextcloud instance. You should regularly back up both the Nextcloud application files and the database. Additionally, consider implementing off-site backups or using cloud storage services for added redundancy.

Q: How can I improve the performance of my Nextcloud installation?

There are several ways to optimize Nextcloud’s performance, including enabling caching mechanisms, configuring database settings, and leveraging content delivery networks (CDNs). The Nextcloud documentation provides detailed guidance on performance optimization techniques.


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Copyright @2022-2024 All Right Reserved – PCPlanet

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. You understand and give your consent that your IP address and browser information might be processed by the security plugins installed on this site. By clicking “Accept”, you consent to the use of ALL the cookies.
Accept Read More

Privacy & Cookies Policy