Introduction
Nextcloud is a self-hosted, open-source collaboration platform that gives you full control over your files, calendars, contacts, and communication. By installing Nextcloud on your Raff VM, you create a private cloud alternative to services like Google Drive, Dropbox, and Microsoft OneDrive — with complete data sovereignty.
Nextcloud offers four core products: Files for file storage and synchronization, Talk for private audio and video conferencing, Groupware for calendars and email, and Office for collaborative document editing. With support for hundreds of community apps, Nextcloud can be extended to cover project management, note-taking, password management, and more.
In this tutorial, you will install Nextcloud on a LAMP stack (Linux, Apache, MariaDB, PHP) with all required PHP modules, configure the database, set file permissions, and complete the web-based setup. By the end, you will have a fully functional private cloud accessible from any browser or the Nextcloud desktop and mobile apps.
Step 1 — Install Apache and PHP Modules
Nextcloud is a PHP application that requires a web server and several PHP extensions. You will use Apache as the web server and install all the PHP modules Nextcloud needs.
Update your package index:
bashsudo apt update
Install Apache, PHP, and the required extensions in a single command:
bashsudo apt install -y apache2 libapache2-mod-php php-gd php-mysql \
php-curl php-mbstring php-intl php-gmp php-bcmath php-xml \
php-imagick php-zip php-bz2 php-apcu php-redis php-common \
imagemagick unzip curl
This installs Apache 2, PHP 8.3 (the default on Ubuntu 24.04), and all extensions required by Nextcloud including image processing, caching, and archive support.
Enable the Apache modules that Nextcloud requires:
bashsudo a2enmod rewrite headers env dir mime setenvif ssl
Restart Apache to load the new modules:
bashsudo systemctl restart apache2
Verify Apache is running:
bashsudo systemctl status apache2
You should see active (running) in the output.
Step 2 — Install and Secure MariaDB
Nextcloud needs a database to store user accounts, file metadata, and application data. MariaDB is the recommended database for Nextcloud on Ubuntu.
Install MariaDB:
bashsudo apt install -y mariadb-server
Run the security hardening script:
bashsudo mysql_secure_installation
Follow the prompts:
- Press Enter when asked for the current root password (there is none by default)
- Type n when asked to switch to unix_socket authentication
- Type Y to set a new root password, then enter a strong password
- Type Y to remove anonymous users
- Type Y to disable remote root login
- Type Y to remove the test database
- Type Y to reload privilege tables
Verify MariaDB is running:
bashsudo systemctl status mariadb
Step 3 — Create the Nextcloud Database
Log into the MariaDB console:
bashsudo mariadb
Create a database, user, and grant privileges. Replace StrongDBPassword with a secure password:
sqlCREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'ncuser'@'localhost' IDENTIFIED BY 'StrongDBPassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
The utf8mb4 character set ensures full Unicode support, including emojis and special characters in file names.
Step 4 — Download and Extract Nextcloud
Download the latest Nextcloud server archive:
bashcd /tmp
curl -O https://download.nextcloud.com/server/releases/latest.zip
Extract the archive to the Apache web root:
bashsudo unzip latest.zip -d /var/www/
Set the correct ownership so Apache can read and write Nextcloud files:
bashsudo chown -R www-data:www-data /var/www/nextcloud
Set secure directory and file permissions:
bashsudo find /var/www/nextcloud/ -type d -exec chmod 750 {} \;
sudo find /var/www/nextcloud/ -type f -exec chmod 640 {} \;
Tip
These permissions follow the principle of least privilege. The owner (www-data) can read and write, the group can read, and others have no access.
Step 5 — Configure the Apache Virtual Host
Create a new Apache virtual host configuration for Nextcloud:
bashsudo nano /etc/apache2/sites-available/nextcloud.conf
Add the following configuration. Replace your_domain_or_ip with your actual domain name or server IP address:
apache<VirtualHost *:80>
DocumentRoot /var/www/nextcloud
ServerName your_domain_or_ip
<Directory /var/www/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>
The AllowOverride All directive allows Nextcloud's .htaccess file to manage URL rewriting and security headers. Disabling mod_dav prevents conflicts with Nextcloud's built-in WebDAV implementation.
Enable the new site and disable the default Apache site:
bashsudo a2ensite nextcloud.conf
sudo a2dissite 000-default.conf
Test the Apache configuration for syntax errors:
bashsudo apache2ctl configtest
Expected output:
Syntax OK
Reload Apache to apply the changes:
bashsudo systemctl reload apache2
Step 6 — Configure PHP for Nextcloud
Nextcloud benefits from specific PHP settings for performance and file upload support. Edit the PHP configuration file used by Apache:
bashsudo nano /etc/php/8.3/apache2/php.ini
Find and adjust the following settings:
inimemory_limit = 512M
upload_max_filesize = 1G
post_max_size = 1G
max_execution_time = 360
date.timezone = UTC
opcache.enable = 1
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.memory_consumption = 128
opcache.save_comments = 1
opcache.revalidate_freq = 1
Note
Adjust upload_max_filesize and post_max_size to match the largest file size your users need to upload. The memory_limit of 512M is the Nextcloud recommended minimum.
Save the file and restart Apache:
bashsudo systemctl restart apache2
Step 7 — Complete the Web-Based Setup
Open your browser and navigate to your server:
http://your_domain_or_ip
You will see the Nextcloud setup page. Fill in the following:
- Admin account: Choose an admin username and a strong password
- Data folder: Leave as the default
/var/www/nextcloud/dataor specify a custom path - Database type: Select MySQL/MariaDB
- Database user:
ncuser - Database password: The password you set in Step 3
- Database name:
nextcloud - Database host:
localhost
Click Install to complete the setup. Nextcloud will initialize the database tables and configure the application. This may take a minute.
After installation completes, you will see the recommended apps page. You can install the suggested apps or click Skip to proceed to your Nextcloud dashboard.
Warning
After completing the web setup, immediately secure the config.php file to protect your database credentials:
bashsudo chmod 660 /var/www/nextcloud/config/config.php
sudo chown root:www-data /var/www/nextcloud/config/config.php
Step 8 — Configure a Cron Job for Background Tasks
Nextcloud requires background tasks to run periodically for file scanning, notification delivery, and cleanup. The recommended method is a system cron job, which is more reliable than the default AJAX method.
Open the crontab for the www-data user:
bashsudo crontab -u www-data -e
Add the following line to run background tasks every 5 minutes:
*/5 * * * * php -f /var/www/nextcloud/cron.php
Save and close the file.
Then, update the Nextcloud setting to use Cron instead of AJAX. Log into your Nextcloud instance as the admin user, navigate to Administration Settings > Basic settings, and select Cron under the Background jobs section.
Step 9 — Verify and Secure the Installation
Log into Nextcloud as the admin user and navigate to Administration Settings > Overview. Nextcloud performs automatic health checks and reports any warnings.
Common post-installation steps to resolve warnings:
Set up the default phone region by adding this line to /var/www/nextcloud/config/config.php:
bashsudo nano /var/www/nextcloud/config/config.php
Add inside the $CONFIG array:
php'default_phone_region' => 'US',
Configure the trusted domains list in the same file. Ensure your domain or IP is listed:
php'trusted_domains' =>
array (
0 => 'your_domain_or_ip',
),
Tip
For production use, you should also secure Nextcloud with HTTPS using a free Let's Encrypt SSL certificate. Run sudo apt install certbot python3-certbot-apache and then sudo certbot --apache -d your_domain to obtain and configure the certificate automatically.
Conclusion
You have installed Nextcloud on your Raff Ubuntu 24.04 VM with a full LAMP stack, configured the database, set secure permissions, and completed the web-based setup. Your private cloud is now ready for file storage, sharing, and collaboration.
From here, you can:
- Secure your instance with a free Let's Encrypt SSL certificate for HTTPS access
- Install the Nextcloud desktop and mobile apps to sync files across all your devices
- Enable Redis caching for improved performance under multi-user workloads
- Configure Raff's automated backup schedule to protect your Nextcloud data
- Install additional apps like Nextcloud Office, Talk, or Calendar from the app store
Raff VMs with NVMe SSD storage deliver the fast disk I/O that Nextcloud needs for file operations and database queries. For a Nextcloud instance serving 5-20 users, the 2 vCPU / 4 GB RAM tier ($19.99/month) with unmetered bandwidth provides a solid foundation.