Skip to content

Web serverFor advanced usersDuration around 30 min.

How to install Nextcloud on your own server: Apache, MariaDB and HTTPS

Nextcloud is file storage, calendar and contacts on your own server. This tutorial installs Nextcloud with Apache, PHP and MariaDB, sets up background jobs and secures access with HTTPS.

Tested on with Nextcloud 35.0 with PHP 8.3 on Ubuntu 24.04 LTS and PHP 8.5 on Ubuntu 26.04 LTS

At a glance

  • Nextcloud requires a web server with PHP and a database; on Ubuntu, the packages from the repository are sufficient.
  • The data directory is located outside the web folder, the installation is handled by occ on the command line.
  • Background jobs run via cron every five minutes, HTTPS is added with Certbot.

Prerequisites

  • A server running Ubuntu 24.04 or 26.04, at least 2 GB memory and enough space for your files โ€” such as a VPS or, for many users, a dedicated server.
  • A domain with an A record pointing to the server โ€” cloud.example.com in the examples โ€”, and open ports 80 and 443.

1. Install Apache, PHP and MariaDB

The package list contains the PHP modules required by Nextcloud, plus APCu as a cache:

Install packages
sudo apt update
sudo apt install -y apache2 mariadb-server libapache2-mod-php php-gd php-mysql php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-zip php-imagick php-apcu unzip

2. Create database

Open the MariaDB console and create the database and user. Replace DB_PASSWORD with your own long password; use exit to exit the console.

Open database
sudo mariadb
In the MariaDB console
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'DB_PASSWORD';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;

3. Download and verify Nextcloud

The checksum ensures that the file is complete and unchanged. The data will later be stored in /var/nextcloud-data, outside the web folder.

Download, verify, extract
cd /tmp
curl -fsSLO https://download.nextcloud.com/server/releases/latest.zip
curl -fsSLO https://download.nextcloud.com/server/releases/latest.zip.sha256
sha256sum -c --ignore-missing latest.zip.sha256
unzip -q latest.zip
sudo mv nextcloud /var/www/nextcloud
sudo mkdir -p /var/nextcloud-data
sudo chown -R www-data:www-data /var/www/nextcloud /var/nextcloud-data

4. PHP settings

Create two files. The version number in the path is 8.3 on Ubuntu 24.04, and 8.5 on Ubuntu 26.04; php -v shows it.

/etc/php/8.3/apache2/conf.d/90-nextcloud.ini
memory_limit = 512M
upload_max_filesize = 2G
post_max_size = 2G
/etc/php/8.3/cli/conf.d/90-nextcloud-apcu.ini
apc.enable_cli = 1

The second file also allows APCu on the command line, where occ and the background jobs run.

5. Set up Apache

Create the site for your domain:

/etc/apache2/sites-available/nextcloud.conf
<VirtualHost *:80>
    ServerName cloud.example.com
    DocumentRoot /var/www/nextcloud
 
    <Directory /var/www/nextcloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
        <IfModule mod_dav.c>
            Dav off
        </IfModule>
    </Directory>
</VirtualHost>

Enable it and the necessary modules, check the configuration and reload Apache:

Enable site and modules
sudo a2ensite nextcloud.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite headers env dir mime
sudo apache2ctl configtest
sudo systemctl reload apache2

6. Install and configure Nextcloud

occ is the Nextcloud command-line tool and always runs as www-data. Enter the database password and your own password for the admin account; the installation ends with the message โ€œNextcloud was successfully installedโ€.

Installation
cd /var/www/nextcloud
sudo -u www-data php occ maintenance:install --database mysql --database-name nextcloud --database-user nextcloud --database-pass 'DB_PASSWORD' --admin-user admin --admin-pass 'ADMIN_PASSWORD' --data-dir /var/nextcloud-data

Then enter the domain, enable the cache and the background jobs via cron:

Domain, cache, cron
sudo -u www-data php occ config:system:set trusted_domains 1 --value=cloud.example.com
sudo -u www-data php occ config:system:set overwrite.cli.url --value=https://cloud.example.com
sudo -u www-data php occ config:system:set memcache.local --value='\OC\Memcache\APCu'
sudo -u www-data php occ background:cron
Cron entry for www-data
echo '*/5 * * * * php -f /var/www/nextcloud/cron.php' | sudo crontab -u www-data -
sudo crontab -u www-data -l

Passwords in the command line

What you enter into the command line ends up in the shell history. Alternatively, open the domain in your browser after step 5 and complete the installer there.

7. HTTPS with Certbot

Certbot fetches a certificate from Letโ€™s Encrypt, adds it to the Apache configuration and renews it automatically. Install Certbot as a snap, as recommended by the project.

Set up certificate
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot
sudo certbot --apache -d cloud.example.com

The status shows whether everything is running:

Check status
sudo -u www-data php /var/www/nextcloud/occ status

Typical errors

  • Access through untrusted domain: The address is missing in trusted_domains. Enter it as in step 6.
  • Message about latest.metadata: The checksum file lists two files. With --ignore-missing, sha256sum only checks the existing one.
  • Note on background jobs in the administration: The cron entry is missing or not running as www-data. Check it with sudo crontab -u www-data -l.
  • Uploading large files aborts: upload_max_filesize and post_max_size are too small or Apache was not reloaded afterwards.

We tested all commands in this guide on 2 December 2026 โ€” with Nextcloud 35.0 with PHP 8.3 on Ubuntu 24.04 LTS and PHP 8.5 on Ubuntu 26.04 LTS. If a step changes at the manufacturer, we update it here along with the date.

Official documentation

Frequently asked questions about Nextcloud

How much memory does Nextcloud need?

For a few users, 2 GB of memory is sufficient. With many users, Office editing or full-text search, you should plan for significantly more.

Why is the data directory outside of /var/www?

Files below the web folder could be directly accessible in case of a configuration error. Outside, only Nextcloud itself serves them.

How do I update Nextcloud?

Via the updater in the administration or on the command line with the Nextcloud updater. Back up the database and data directory beforehand.

Does this also work with Nginx instead of Apache?

Yes, Nextcloud also runs with Nginx and PHP-FPM. The configuration is more complex because Nginx does not read .htaccess files.

Is there a faster way?

Nextcloud is also available as a snap package or as an All-in-One container. However, the method in this tutorial shows every setting and fits your own requirements.

Further reading

More tutorials

  • How to set up Nginx as a reverse proxy with HTTPS (Letโ€™s Encrypt)

    Web serverFor beginnersabout 20 min

    Following this tutorial, Nginx will accept requests to your domain, pass them to an application on the same server, and serve everything over HTTPS with a Letโ€™s Encrypt certificate. This is suitable for Node.js, Python, Go, or a container listening on a local port.

  • How to install WordPress on your own server: Nginx, PHP and MariaDB

    Web serverFor advanced usersabout 30 min

    This tutorial brings WordPress to your own server with Ubuntu: Nginx as the web server, PHP-FPM for WordPress, MariaDB as the database and a certificate from Letโ€™s Encrypt. Finally, you will complete the setup in the browser, where you create the title and administrator.

A server for your Nextcloud

Nextcloud runs on a VPS for family and team; for many users, a dedicated server offers more resources.