
Taking control of your own data is a decisive step away from relying on big tech for your cloud storage. By hosting your own files, calendars, and contacts, you gain complete sovereignty over your digital life. Nextcloud stands out as a leading open-source platform that allows you to build a private cloud tailored to your needs. This comprehensive Nextcloud setup guide will walk you through every step to install Nextcloud on Ubuntu Server 24.04, turning your Contabo VPS into a secure and versatile data hub.
If you’re just getting started with your server, understanding the setup and benefits of the Ubuntu Server operating system can provide a solid foundation before you begin this installation.
Building Your Private Cloud with a Production-Grade Nextcloud Installation
Before we begin, it’s helpful to understand what is Nextcloud at its core. Nextcloud is a powerful, open-source suite of client-server software that allows you to create a completely private, self-hosted cloud. Think of it as an alternative to commercial services like Google Drive, Dropbox, and Microsoft 365, but one where you have complete control and ownership of your data. It provides file synchronization and sharing, integrated calendar and contact management, and can be expanded with hundreds of apps for everything from collaborative document editing to video conferencing.
As Nextcloud is designed to handle such critical data, this Nextcloud install guide focuses on creating a production-ready environment from the ground up. We’ll go beyond the bare minimum to implement the configurations necessary for a secure, efficient, and scalable setup suitable for daily use. A proper Nextcloud installation should be something you can rely on, and following these steps will ensure your private cloud is built on a solid foundation, ready to protect and serve your data effectively.
Nextcloud Server – System and Database Prerequisites
Before we can install Nextcloud itself, we must prepare the server environment. A stable and correctly configured foundation is essential for meeting the Nextcloud system requirements and ensuring a smooth installation. This section covers all the Nextcloud prerequisites, focusing on the web server and database components. For this guide, we will use a classic LAMP stack (Linux, Apache, MariaDB, and PHP) and walk through how to install Apache2 and MariaDB on your Ubuntu server.
System Update
First, it is always best practice to start with a fully updated system. This ensures you have the latest security patches and software versions. Connect to your server via SSH and run the following command:
sudo apt update && sudo apt upgrade -y
Install Apache and PHP
Nextcloud is a PHP-based application, so it requires a web server and the correct PHP modules to function. We will use Apache2 as our web server. This single command will install Apache, PHP, and all the extensions required by Nextcloud:
sudo apt install apache2 libapache2-mod-php php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip php-gmp php-bcmath -y
Install and Secure MariaDB
For the database, we will use MariaDB, a popular and powerful open-source relational database that is a drop-in replacement for MySQL.
Install the MariaDB server package with this command:
sudo apt install mariadb-server -y
After the installation, MariaDB comes with a security script that helps you set a root password, remove anonymous users, and disable remote root login. This is a critical step for securing your database server.
Run the script and follow the prompts:
sudo mysql_secure_installation
You will be asked to set a root password, remove anonymous users, disallow root login remotely, and remove the test database. It is recommended to answer ‘Y’ (yes) to all these questions for a secure setup.
Create the Nextcloud Database
With MariaDB secured, we need to create a dedicated database and a database user for Nextcloud. Using a dedicated user improves security by isolating Nextcloud’s data.
First, log in to the MariaDB command line as the root user:
sudo mysql -u root -p
Enter the root password you created in the previous step. Once you are at the MariaDB prompt, execute the following commands one by one. Be sure to replace your_strong_password
with a strong and unique password you generate for the database user.
Create the database:
CREATE DATABASE nextcloud;
Create the dedicated user and set its password:
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'your_strong_password';
Grant the new user full permissions on the Nextcloud database:
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
Apply the changes and exit the MariaDB prompt:
FLUSH PRIVILEGES;
EXIT;
With the server environment fully prepared, we are now ready to download Nextcloud and configure it.
How To Configure Nextcloud
With the server prerequisites correctly configured, we can now proceed with the main event: getting the Nextcloud application itself onto the server. This process involves downloading the software, placing it in the correct location, and running the installer to connect it with the database we created.
Download and Unpack Nextcloud
We will download the latest stable release directly from the Nextcloud website. It’s best to do this in a temporary directory like /tmp
.
First, change to the /tmp
directory:
cd /tmp
Use wget
to download the compressed Nextcloud package. This link always points to the latest stable version:
wget https://download.nextcloud.com/server/releases/latest.zip
Once the download is complete, you’ll need the unzip utility to extract the package. Install it if you don’t have it already:
sudo apt install unzip -y
Now, unpack the archive:
unzip latest.zip
This will create a new directory named nextcloud
.
Set Up Web and Data Directories
Next, we need to move the application files to the web server’s document root, which is /var/www/html/
.
sudo mv nextcloud /var/www/html/
A critical part of a secure installation is managing the Nextcloud data directory. This is where all user files, thumbnails, and other data are stored. For security reasons, this directory should never be located inside the web root where it could be accessed directly from a browser. We will create it in a separate location. A common choice is /var/
.
Create the data directory:
sudo mkdir /var/nextcloud-data
Now, we must grant the web server user, www-data
, ownership of both the Nextcloud application and data directories so it can read and write files.
sudo chown -R www-data:www-data /var/www/html/nextcloud/
sudo chown -R www-data:www-data /var/nextcloud-data/
Finalize Installation with the CLI
The final step is to run the Nextcloud installer. While this can be done through a web browser, it’s more reliable and efficient to configure Nextcloud with the CLI. This method uses the occ (ownCloud console) script and avoids potential web server or browser timeouts, especially on initial setup.
Navigate to the Nextcloud application directory:
cd /var/www/html/nextcloud
Now, run the installation command. This single command will tell Nextcloud everything it needs to know: the admin account details, the database credentials, and the location of the data directory.
Execute the command as the www-data
user. Make sure to replace your_strong_password
with the database password you created earlier, and set a new, strong your_admin_password
for your Nextcloud administrator account.
sudo -u www-data php occ maintenance:install --database "mysql" --database-name "nextcloud" --database-user "nextclouduser" --database-pass "your_strong_password" --admin-user "admin" --admin-pass "your_admin_password" --data-dir "/var/nextcloud-data"
After running the command, you should see a confirmation message: “Nextcloud was installed successfully.” Your Nextcloud instance is now installed and ready for optimization.
Optimizing Nextcloud with PHP-FPM, Caching, and Background Jobs
A fresh Nextcloud installation is functional, but to unlock its true potential and ensure a fast, responsive experience, we need to perform some key optimizations. A production-grade server should handle requests efficiently, use memory caching to speed up data retrieval, and manage background tasks reliably. This section covers three critical areas: switching to Nextcloud PHP-FPM, implementing a Nextcloud APCu cache and a Nextcloud Redis cache, and setting up a proper Nextcloud cron job.
Using PHP-FPM for Better Performance
By default, Apache uses a module called mod_php
to handle PHP code. While simple, a more modern and performant approach is to use PHP-FPM (FastCGI Process Manager). PHP-FPM runs as a separate service, which can lead to lower memory consumption and better overall performance, especially under load.
First, install the PHP-FPM package:
sudo apt install php-fpm -y
Next, we need to configure Apache to use it. We’ll enable the necessary Apache modules, enable the PHP-FPM configuration that was just installed, and then disable the old mod_php
. Ubuntu 24.04 uses PHP 8.4, so the commands are version-specific.
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo a2dismod php8.4
Finally, restart Apache for the changes to take effect:
sudo systemctl restart apache2
Configuring Memory Caching with APCu and Redis
Memory caching is arguably the most significant performance enhancement you can make for Nextcloud. It stores frequently requested data in RAM, which is much faster than retrieving it from the database or disk every time. We will configure two types of cache:
- APCu: A local cache for storing compiled PHP bytecode. This speeds up the application itself.
- Redis: A powerful in-memory data store that we will use for file locking and distributed caching, which prevents data corruption during simultaneous operations and improves performance.
First, install Redis and the required PHP module for it:
sudo apt install redis-server php-redis -y
Next, we tell Nextcloud to use these caching systems by editing its configuration file. Open config.php
with a text editor:
sudo nano /var/www/html/nextcloud/config/config.php
Add the following lines just before the final ); in the file:
'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
'host' => 'localhost',
'port' => 6379,
],
Save and close the file by pressing CTRL+X
, then Y
, and Enter
.
Setting Up a System Cron Job
Nextcloud needs to run background tasks regularly for things like database cleanup, checking for updates, and processing notifications. The default method, “AJAX,” only runs these jobs when a user is actively browsing the site, which can be unreliable. The recommended method is to use a system cron job that runs at a fixed interval.
First, use the occ
command to tell Nextcloud to use the “cron” method for background jobs:
sudo -u www-data php /var/www/html/nextcloud/occ background:cron
Now, we need to create a cron job that runs as the www-data
user. Open the crontab editor for this user:
sudo crontab -u www-data -e
If prompted, choose a text editor (nano is a good choice). Add the following line to the bottom of the file. This command will execute the Nextcloud cron script every five minutes.
*/5 * * * * php -f /var/www/html/nextcloud/cron.php
Save and close the file. Your Nextcloud instance is now fully optimized for performance and reliability.
Securing Your Nextcloud Server with HTTPS and Firewall
An optimized server is a great start, but a secure one is non-negotiable, especially when it’s hosting your private data. This section covers two of the most important first steps in securing your instance: encrypting web traffic to enable Nextcloud HTTPS and configuring a basic Nextcloud firewall to block unwanted access. These steps are fundamental for any production server, and for those looking to further harden their system, our guide on how you can improve the security of your server offers more advanced techniques.
Enabling HTTPS with a Nextcloud SSL Letsencrypt Certificate
Right now, your Nextcloud site is accessible via HTTP, which sends all data, including your login credentials, in plain text. Enabling HTTPS encrypts the connection between your browser and the server, making it secure. We will use a free Nextcloud SSL Letsencrypt certificate to achieve this. Let’s Encrypt is a non-profit Certificate Authority that provides an easy and automated way to obtain and renew SSL/TLS certificates.
We will use the Certbot client, which simplifies the entire process.
First, install Certbot and its Apache plugin:
sudo apt install certbot python3-certbot-apache -y
Next, run Certbot. It will automatically detect your domain configuration from Apache, ask you a few questions, and install the certificate.
sudo certbot --apache
The script will guide you through the process. You will need to:
- Enter your email address for renewal notices.
- Agree to the Let’s Encrypt Terms of Service.
- Choose whether to share your email with the Electronic Frontier Foundation.
- Select the domain name you want to secure.
When prompted about redirecting HTTP traffic to HTTPS, it is highly recommended to select the redirect option. This ensures all connections to your site are automatically secured. After you finish, Certbot will have configured SSL for you, and it also sets up an automatic renewal process.
Configuring a Basic Firewall
A firewall is a critical security layer that controls network traffic to and from your server. We will use UFW (Uncomplicated Firewall), Ubuntu’s default firewall management tool, to allow only the traffic we need.
First, we will create rules to allow SSH (so you don’t get locked out of your server) and web traffic (HTTP and HTTPS).
Allow SSH connections:
sudo ufw allow OpenSSH
Allow web traffic through Apache. The ‘Apache Full’ profile opens both port 80 (HTTP) and port 443 (HTTPS):
sudo ufw allow 'Apache Full'
Now that the essential rules are in place, you can enable the firewall. It is very important to allow OpenSSH before enabling UFW.
sudo ufw enable
Press y to confirm. You can check the status of your firewall at any time with the following command:
sudo ufw status
This will show a list of your active rules, confirming that your server is now protected by a basic but effective firewall.
Connecting Your Devices: Nextcloud Desktop and Mobile Clients
The true power of your private cloud is unlocked when you can seamlessly access and synchronize your data across all your devices. Nextcloud provides excellent, free applications to make this happen.
The Nextcloud desktop client, available for Windows, macOS, and Linux, integrates your cloud directly into your computer’s file system. It creates a local folder that is kept in constant sync with the server, giving you offline access to your files and automatically uploading any changes you make. This provides an experience similar to commercial services like Dropbox or Google Drive.
Likewise, the Nextcloud mobile app for Android and iOS brings your cloud to your phone or tablet. You can browse your files, share them with others, and automatically upload photos and videos as you take them—a perfect way to back up your memories privately. The mobile app also provides access to your Nextcloud Calendar, Contacts, and other integrated features.
To get started, simply download the appropriate application for your device, and sign in using your server URL, username, and password.
Conclusion
By following this guide, you have successfully deployed a secure, high-performance, and fully functional private cloud. You’ve moved beyond a simple installation to build a robust foundation for managing your digital life or your team’s collaborative efforts. Your new self-hosted Nextcloud instance is now a powerful asset, giving you complete control over your files, calendars, contacts, and more, all while running on your own Contabo server.
This setup is just the beginning. The true power of Nextcloud lies in its flexibility and the vast ecosystem of apps available to extend its functionality. From collaborative office document editing to private video calls, you have a platform that can grow with your needs.
Building your own server provides ultimate control, and while this guide empowers you to do just that, we also understand that time is valuable. If you’re looking for a solution with hardware specifically optimized for performance right from the start, our dedicated Nextcloud Hosting plans offer a powerful and convenient alternative.
Ultimately, you have taken a significant step toward data sovereignty. Enjoy the freedom and peace of mind that comes with owning your cloud.
Nextcloud on Ubuntu FAQ
What are the recommended system requirements for Nextcloud?
For a small, personal instance with a few users, a server with 2 CPU cores and 2-4 GB of RAM is a great starting point. For larger teams or more intensive use with apps like Nextcloud Office, we recommend a server with at least 4 CPU cores and 8 GB of RAM to ensure smooth performance.
Can I use Nginx instead of Apache?
Absolutely. Nextcloud works very well with Nginx, which is another high-performance web server. However, the configuration process is different from this guide. You would need to create an Nginx server block configuration file and configure it to handle PHP requests via PHP-FPM. The official Nextcloud documentation provides example configurations for Nginx.
How do I update Nextcloud to a new version?
Nextcloud has a built-in updater that you can access from the administration settings in the web interface. It will notify you when a new version is available. You can also perform updates via the command line using the occ
tool. It is always strongly recommended to create a full backup of your Nextcloud files, data directory, and database before starting an update.
I made a mistake in the config.php file. How can I fix it?
If a configuration error prevents you from accessing your Nextcloud instance, you can always edit the file directly on the server. Connect via SSH and use a command-line editor like nano to open the file: sudo nano /var/www/html/nextcloud/config/config.php
. You can then correct the mistake, save the file, and your instance should become accessible again.
How can I add more storage space to my Nextcloud server?
One of the benefits of using a Contabo VPS is the ability to easily scale your resources. If you find yourself running low on storage, you can upgrade your VPS plan to one with a larger disk. After the upgrade, you may need to resize your server’s partition to make use of the new space, which can be done using standard Linux tools like growpart
and resize2fs
.