How to Install and Configure Nextcloud on Ubuntu 24.04
Learn how to install and configure Nextcloud on Ubuntu 24.04 LTS with Apache, MariaDB, PHP 8.3, Redis cache, and automated Let's Encrypt SSL encryption.

6 min read
Learn how to install and configure Nextcloud on Ubuntu 24.04 LTS with Apache, MariaDB, PHP 8.3, Redis cache, and automated Let's Encrypt SSL encryption.
- Prerequisites and Supported Releases
- Step 1: Updating System Packages and Installing Apache and MariaDB
- Step 2: Creating Dedicated Nextcloud Database and User
Nextcloud Hub is the leading self-hosted, open-source content collaboration and file synchronization platform in the digital privacy ecosystem. Providing an enterprise-grade private alternative to proprietary cloud storage services like Google Drive, Dropbox, Microsoft OneDrive, and Box, Nextcloud delivers secure file storage, real-time document editing (via Collabora Online or OnlyOffice), synchronized calendars, contacts, task boards, and audio/video conferencing through Nextcloud Talk.
Deploying Nextcloud on your own Ubuntu infrastructure gives you complete, auditable control over intellectual property and confidential customer records without recurring licensing fees. Understanding how to install and configure nextcloud on ubuntu 24.04 empowers businesses and individuals to maintain a private, compliant cloud workspace for file synchronization, collaborative office editing, and secure sharing.
In this step-by-step tutorial, we demonstrate how to install and configure Nextcloud on Ubuntu 24.04 LTS (Noble Numbat). We cover deploying the LAMP stack (Apache HTTP server, MariaDB relational database, and PHP 8.3), installing required PHP modules, configuring Redis for distributed memory caching and file locking, extracting Nextcloud into /var/www/nextcloud, isolating media storage in /var/nextcloud_data, creating Apache virtual hosts, and hardening security with Let's Encrypt SSL.
Deploy and configure a production-ready Nextcloud collaboration and cloud storage hub on Ubuntu 24.04 LTS with Apache, MariaDB, PHP 8.3, Redis in-memory cache, and SSL.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A server or virtual machine running
Ubuntu 24.04 LTS. - A non-root user account configured with administrative
sudoprivileges. - A registered domain name (e.g.,
cloud.example.com) pointed to your server IP address. - At least
2 GB of RAM(4 GB recommended for real-time document collaboration and high-volume file syncing).
Step 1: Updating System Packages and Installing Apache and MariaDB
Nextcloud operates on the classic LAMP stack architecture. Start by updating your local APT repository index and installing the Apache web server, MariaDB database server, and archive extraction tools.
Install apache2, mariadb-server, unzip, and essential network utilities.
Enable both services to launch automatically at system startup, and verify their active status.
# Update repository indices and upgrade packages
sudo apt update && sudo apt upgrade -y
# Install Apache, MariaDB, and extraction tools
sudo apt install -y apache2 mariadb-server mariadb-client unzip curl bzip2
# Enable and verify services
sudo systemctl enable --now apache2 mariadb
sudo systemctl status apache2 mariadb --no-pager
Step 2: Creating Dedicated Nextcloud Database and User
Nextcloud requires a relational database to store user credentials, folder hierarchies, activity logs, calendar entries, and file metadata.
Log into the MariaDB shell as the administrative root user.
Create a dedicated database named nextcloud_db with utf8mb4 encoding, create the database user nextcloud_user, grant full privileges, and flush privileges.
Replace StrongNextcloudPass123! with a strong, randomized password.
-- Access MariaDB root shell
sudo mariadb
-- Create Nextcloud database with utf8mb4 encoding
CREATE DATABASE nextcloud_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
-- Create dedicated database user
CREATE USER 'nextcloud_user'@'localhost' IDENTIFIED BY 'StrongNextcloudPass123!';
-- Grant privileges on Nextcloud database
GRANT ALL PRIVILEGES ON nextcloud_db.* TO 'nextcloud_user'@'localhost';
-- Flush privilege tables and exit
FLUSH PRIVILEGES;
EXIT;
Step 3: Installing PHP 8.3 and Required Nextcloud Extensions
Ubuntu 24.04 features PHP 8.3 as its default runtime. Nextcloud requires PHP along with specialized modules for image processing, database interaction, internationalization, XML parsing, and ZIP archive extraction.
Install PHP 8.3 and the required extensions: libapache2-mod-php, php-mysql, php-curl, php-gd, php-intl, php-mbstring, php-xml, php-zip, php-bcmath, php-gmp, and php-imagick.
Tune PHP settings in /etc/php/8.3/apache2/php.ini: set memory_limit = 512M, upload_max_filesize = 16G, post_max_size = 16G, max_execution_time = 360, and enable opcache.enable=1.
Restart Apache to apply the new PHP runtime configuration.
# Install PHP and essential Nextcloud modules
sudo apt install -y php libapache2-mod-php php-mysql php-curl php-gd php-intl php-mbstring php-xml php-zip php-bcmath php-gmp php-imagick php-bz2 php-redis
# Configure recommended PHP memory and upload parameters
sudo sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php/8.3/apache2/php.ini
sudo sed -i 's/upload_max_filesize = .*/upload_max_filesize = 16G/' /etc/php/8.3/apache2/php.ini
sudo sed -i 's/post_max_size = .*/post_max_size = 16G/' /etc/php/8.3/apache2/php.ini
sudo sed -i 's/max_execution_time = .*/max_execution_time = 360/' /etc/php/8.3/apache2/php.ini
# Restart Apache
sudo systemctl restart apache2
Step 4: Installing and Configuring Redis for In-Memory Caching
To optimize file locking performance and eliminate database query bottlenecks during heavy concurrent file syncing, deploy Redis as a local in-memory caching backend.
Install the redis-server package using APT.
Configure Redis to use Unix sockets for lowest latency, add the www-data user to the redis group, and verify the service status.
# Install Redis server
sudo apt install -y redis-server
# Enable and verify Redis service
sudo systemctl enable --now redis-server
sudo usermod -aG redis www-data
sudo systemctl restart redis-server
Step 5: Downloading and Extracting Nextcloud Archive
Download the latest stable release archive of Nextcloud directly from the official Nextcloud distribution server into your /tmp directory.
Extract the archive into your web root directory at /var/www/nextcloud.
Create a dedicated, isolated data directory at /var/nextcloud_data outside the web document root to prevent unauthorized direct HTTP file downloads.
Assign ownership of both directories to the www-data web server user.
# Download latest Nextcloud archive
cd /tmp
wget https://download.nextcloud.com/server/releases/latest.tar.bz2
# Extract into /var/www/
sudo tar -xjf latest.tar.bz2 -C /var/www/
# Create external data directory
sudo mkdir -p /var/nextcloud_data
# Set ownership and permissions
sudo chown -R www-data:www-data /var/www/nextcloud /var/nextcloud_data
sudo chmod -R 750 /var/www/nextcloud /var/nextcloud_data
# Clean up archive
rm -f /tmp/latest.tar.bz2
Step 6: Configuring Apache Virtual Host for Nextcloud
Create a new Apache Virtual Host configuration file at /etc/apache2/sites-available/nextcloud.conf.
Define the DocumentRoot pointing to /var/www/nextcloud, configure your domain name, and enable .htaccess overrides.
Enable required Apache modules: rewrite, headers, env, dir, and mime.
Enable the site and restart Apache.
# Create Apache Virtual Host configuration
sudo bash -c 'cat <<EOF > /etc/apache2/sites-available/nextcloud.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/nextcloud
ServerName cloud.example.com
<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>
EOF'
# Enable Apache modules and site configuration
sudo a2enmod rewrite headers env dir mime
sudo a2ensite nextcloud.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2
Step 7: Securing Nextcloud with Let's Encrypt SSL via Certbot
Nextcloud strictly mandates encrypted HTTPS connections to protect authentication cookies, desktop sync tokens, and uploaded documents.
Install Certbot and the Apache Certbot plugin to automate certificate acquisition.
Request and apply a free Let's Encrypt SSL certificate for your Nextcloud domain with automatic HTTPS redirection.
Test certificate renewal using a dry run.
# Install Certbot and Apache plugin
sudo apt install -y certbot python3-certbot-apache
# Request and install SSL certificate
sudo certbot --apache -d cloud.example.com --non-interactive --agree-tos -m [email protected] --redirect
# Test automatic renewal
sudo certbot renew --dry-run
Step 8: Completing Nextcloud Web Installation and Finalizing Cache
Open your web browser and navigate to https://cloud.example.com to complete the graphical setup wizard.
Create your primary administrator account by specifying an admin username and a strong master password.
Set the Data folder path to /var/nextcloud_data.
Under Database user, enter nextcloud_user, enter your database password, database name nextcloud_db, and keep localhost.
Click Install to initialize Nextcloud schemas.
After installation completes, append the Redis memory cache settings to /var/www/nextcloud/config/config.php using the occ command.
# Configure Redis memory cache using occ CLI utility
sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.local --value "\\OC\\Memcache\\APCu"
sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.distributed --value "\\OC\\Memcache\\Redis"
sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.locking --value "\\OC\\Memcache\\Redis"
sudo -u www-data php /var/www/nextcloud/occ config:system:set redis host --value "127.0.0.1"
sudo -u www-data php /var/www/nextcloud/occ config:system:set redis port --value 6379 --type integer
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
Nextcloud admin overview warns: 'The PHP memory limit is below the recommended value of 512MB'
Resolution: Open /etc/php/8.3/apache2/php.ini and ensure memory_limit = 512M is set. Restart Apache: sudo systemctl restart apache2.
WebDAV interface error or desktop sync client reports '405 Method Not Allowed'
Resolution: Ensure WebDAV is disabled in Apache for Nextcloud's path by verifying Dav off is inside /etc/apache2/sites-available/nextcloud.conf. Nextcloud provides its own internal SabreDAV engine.
Uploads halt at 2 MB or fail with 'Upload error: Request Entity Too Large'
Resolution: Adjust both upload_max_filesize and post_max_size in /etc/php/8.3/apache2/php.ini (e.g., set to 16G). Increase the timeout parameters and restart Apache.
Security Best Practices and Hardening
Always store the Nextcloud data directory (/var/nextcloud_data) outside the web root directory to prevent direct URL access to uploaded files.
Enable Two-Factor Authentication (2FA) for all user and admin accounts in Nextcloud Apps > Security > Two-Factor TOTP Provider.
Add your domain explicitly to the 'trusted_domains' array in /var/www/nextcloud/config/config.php to prevent HTTP Host header poisoning attacks.
Regularly backup the MariaDB database using mysqldump and backup the /var/nextcloud_data folder alongside config.php.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install and Secure MariaDB on Ubuntu 24.04
- How to Install and Configure ownCloud on Ubuntu 24.04
Authoritative References and Official Documentation

UNIX and Linux System Administration Handbook, 5th Edition
Frequently Asked Questions
Quick answers to common questions and configurations
crontab -u www-data -e and append */5 * * * * php -f /var/www/nextcloud/cron.php.sudo -u www-data php /var/www/nextcloud/updater/updater.phar followed by sudo -u www-data php /var/www/nextcloud/occ upgrade.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!