To install Nextcloud on Ubuntu 24.04 LTS, set up a LAMP/LEMP stack with PHP 8.3, create a database, download the latest Nextcloud to /var/www/nextcloud, configure Apache or Nginx with HTTPS, enable Redis caching and cron, then complete the web installer. This 2026 step by step guide covers optimal settings, security, and performance.
This complete guide shows how to install Nextcloud on Ubuntu 24.04 LTS using best practices for 2026. You’ll learn the fastest, most secure way to deploy Nextcloud with Apache or Nginx, PHP 8.3, MariaDB or PostgreSQL, Redis, Let’s Encrypt SSL, and cron—plus hardening and performance tips proven in real world production.
What is Nextcloud and why Ubuntu 24.04 LTS?
Nextcloud is a self hosted, private cloud platform for file sync, sharing, Office/Collabora, Talk, calendars, and more. Ubuntu 24.04 LTS (Noble) ships with current, secure packages (PHP 8.3, OpenSSL 3) and a 5 year support window ideal for a stable, future proof Nextcloud stack in 2026.
Prerequisites and system requirements
- An Ubuntu 24.04 LTS server (1–2 vCPU, 2–4 GB RAM minimum; 8+ GB RAM recommended for large teams)
- A domain or subdomain (e.g., cloud.example.com) pointing to the server’s public IP
- SSH access with sudo privileges
- Open ports: 80/tcp and 443/tcp
- Optional: Swap enabled on low RAM VPS, and a separate data disk for Nextcloud data
For business grade performance, choose SSD/NVMe storage and enable server side caching (Redis). Managed NVMe VPS from YouStable includes Ubuntu 24.04 images, free SSL, and support that can pre install this stack on request.
Step 1 – Update server and set hostname
sudo apt update && sudo apt -y upgrade
sudo hostnamectl set-hostname cloud
sudo apt -y install ufw unzip bzip2 curl software-properties-common
Enable the firewall and allow web traffic:
sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status
Step 2 – Choose your web server: Apache or Nginx
Apache is beginner friendly and integrates cleanly with Certbot. Nginx is lean and performs excellently at scale. Both are fully supported by Nextcloud.
Option A: Install Apache (recommended for most users)
sudo apt -y install apache2 libapache2-mod-fcgid
Option B: Install Nginx (performance focused)
sudo apt -y install nginx
Step 3 – Install PHP 8.3 and required extensions
Nextcloud requires PHP 8.1+; Ubuntu 24.04 provides PHP 8.3. Install FPM plus all needed extensions:
sudo apt -y install php8.3-fpm php8.3-cli php8.3-gd php8.3-curl php8.3-xml php8.3-zip \
php8.3-mbstring php8.3-bz2 php8.3-intl php8.3-gmp php8.3-bcmath php8.3-imap \
php8.3-redis php8.3-apcu php8.3-imagick
Tune PHP for Nextcloud:
sudo sed -i 's/^memory_limit.*/memory_limit = 512M/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/^upload_max_filesize.*/upload_max_filesize = 2G/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/^post_max_size.*/post_max_size = 2G/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/^max_execution_time.*/max_execution_time = 360/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/;opcache.enable=1/opcache.enable=1/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/;opcache.memory_consumption=.*/opcache.memory_consumption=256/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/;opcache.interned_strings_buffer=.*/opcache.interned_strings_buffer=16/' /etc/php/8.3/fpm/php.ini
sudo sed -i 's/;opcache.max_accelerated_files=.*/opcache.max_accelerated_files=10000/' /etc/php/8.3/fpm/php.ini
sudo systemctl restart php8.3-fpm
Step 4 – Install and prepare the database
You can use MariaDB/MySQL or PostgreSQL. Both work well; PostgreSQL scales very nicely for larger instances.
Option A: MariaDB
sudo apt -y install mariadb-server
sudo mysql_secure_installation
Create a database and user:
sudo mysql -u root -p
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'ncuser'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Option B: PostgreSQL
sudo apt -y install postgresql
sudo -u postgres psql -c "CREATE USER ncuser WITH PASSWORD 'StrongPasswordHere';"
sudo -u postgres psql -c "CREATE DATABASE nextcloud TEMPLATE template0 ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' OWNER ncuser;"
Step 5 – Download and place Nextcloud
cd /tmp
curl -O https://download.nextcloud.com/server/releases/latest.tar.bz2
curl -O https://download.nextcloud.com/server/releases/latest.tar.bz2.asc
# (Optional) Import & verify signature per Nextcloud docs
sudo tar -xjf latest.tar.bz2 -C /var/www/
sudo chown -R www-data:www-data /var/www/nextcloud
sudo find /var/www/nextcloud/ -type d -exec chmod 750 {} \;
sudo find /var/www/nextcloud/ -type f -exec chmod 640 {} \;
Step 6 – Configure your web server
Apache virtual host (PHP-FPM)
Create a site file at /etc/apache2/sites-available/nextcloud.conf (replace cloud.example.com):
sudo tee /etc/apache2/sites-available/nextcloud.conf >/dev/null <<'EOF'
<VirtualHost *:80>
ServerName cloud.example.com
DocumentRoot /var/www/nextcloud
<Directory /var/www/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost/"
</FilesMatch>
<IfModule mod_headers.c>
Header always set Referrer-Policy "no-referrer"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block"
</IfModule>
ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>
EOF
sudo a2enmod rewrite headers env dir mime proxy_fcgi setenvif
sudo a2ensite nextcloud
sudo systemctl reload apache2
Nginx server block
Create /etc/nginx/sites-available/nextcloud and enable it (replace cloud.example.com):
sudo tee /etc/nginx/sites-available/nextcloud >/dev/null <<'EOF'
server {
listen 80;
server_name cloud.example.com;
root /var/www/nextcloud;
index index.php;
client_max_body_size 2G;
fastcgi_buffers 64 4K;
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
location = /robots.txt { allow all; log_not_found off; access_log off; }
location = /.well-known/carddav { return 301 /remote.php/dav; }
location = /.well-known/caldav { return 301 /remote.php/dav; }
location / {
try_files $uri $uri/ /index.php$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ \.php(?:$|/) {
include snippets/fastcgi-php.conf;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ \.(?:css|js|woff2?|svg|gif)$ {
try_files $uri /index.php$request_uri;
expires 6M; access_log off;
}
location ~ \.(?:png|jpg|jpeg|ico|webp)$ {
try_files $uri /index.php$request_uri;
expires 6M; access_log off;
}
error_log /var/log/nginx/nextcloud_error.log;
access_log /var/log/nginx/nextcloud_access.log;
}
EOF
sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Step 7 – Enable HTTPS with Let’s Encrypt
Issue and auto renew a free SSL certificate.
# Apache
sudo apt -y install certbot python3-certbot-apache
sudo certbot --apache -d cloud.example.com
# Nginx
sudo apt -y install certbot python3-certbot-nginx
sudo certbot --nginx -d cloud.example.com
# Test renewal
sudo systemctl list-timers | grep certbot
Step 8 – Configure Redis caching and file locking
Redis prevents file locking issues and boosts performance.
sudo apt -y install redis-server
sudo sed -i 's/^supervised .*/supervised systemd/' /etc/redis/redis.conf
sudo systemctl enable --now redis-server
Add caching to Nextcloud’s config.php:
sudo -u www-data php /var/www/nextcloud/occ maintenance:install --database "mysql" \
--database-name "nextcloud" --database-user "ncuser" --database-pass "StrongPasswordHere" \
--admin-user "admin" --admin-pass "AnotherStrongPassword"
sudo -u www-data php -r '
$cfg="/var/www/nextcloud/config/config.php";
$c=include $cfg;
$c["memcache.local"]="\\OC\\Memcache\\APCu";
$c["memcache.locking"]="\\OC\\Memcache\\Redis";
$c["redis"]=["host"=>"127.0.0.1","port"=>6379];
$c["default_phone_region"]="US";
file_put_contents($cfg,"<?php\nreturn ".var_export($c,true).";\n");'
If you prefer PostgreSQL, change the maintenance:install flags accordingly (database=pgsql).
Step 9 – Set up background jobs (cron)
sudo -u www-data crontab -e
# Add:
*/5 * * * * php -f /var/www/nextcloud/cron.php >/dev/null 2>&1
In Settings > Basic settings, switch Background jobs to “Cron.”
Step 10 – Secure permissions and hardening
- Run Nextcloud under www-data
- Disable directory listing
- Force HTTPS with HSTS
- Isolate the data folder on a separate disk when possible
- Keep regular, offsite backups
# Permissions
sudo chown -R www-data:www-data /var/www/nextcloud
sudo find /var/www/nextcloud/ -type d -exec chmod 750 {} \;
sudo find /var/www/nextcloud/ -type f -exec chmod 640 {} \;
# UFW profile for Apache or Nginx is already allowed; ensure SSH/HTTPS stay open
sudo ufw status
# Optional: enable HSTS on Apache (inside VirtualHost after SSL is active)
# Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Step 11 – Complete the web installer
Visit https://cloud.example.com and log in as the admin user you created (or create via the web form). Point the data directory to the default (/var/www/nextcloud/data) or an attached volume with sufficient space. Confirm the database credentials and finish installation.
Post install commands and checks
# Add your domain to trusted domains
sudo -u www-data php /var/www/nextcloud/occ config:system:set trusted_domains 1 --value=cloud.example.com
# Enable recommended preview providers (speeds up thumbnails)
sudo -u www-data php /var/www/nextcloud/occ config:app:set previewgenerator squareSizes --value="32 256"
sudo -u www-data php /var/www/nextcloud/occ config:app:set previewgenerator widthSizes --value="256 384 512 768 1024"
sudo -u www-data php /var/www/nextcloud/occ config:app:set previewgenerator heightSizes --value="256 384 512 768 1024"
# Add missing DB indexes (if prompted in Admin > Overview)
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices
# Verify background jobs
sudo -u www-data php /var/www/nextcloud/occ background:status
Performance tuning checklist (2026 best practices)
- Use PHP 8.3-FPM with OPcache and APCu
- Enable Redis for local cache and file locking
- Set client_max_body_size/upload_max_filesize to match your largest files
- Use HTTP/2 (default with modern Apache/Nginx on TLS)
- Place data on fast NVMe storage; consider object storage for large deployments
- PostgreSQL for big/complex instances; MariaDB for simplicity
- Prefer Nginx for very high concurrency setups
- Schedule previews generation during off peak hours
Troubleshooting essentials
- Logs: /var/www/nextcloud/data/nextcloud.log
- Web server logs: /var/log/apache2/*.log or /var/log/nginx/*.log
- PHP-FPM logs: journalctl -u php8.3-fpm
- Permissions: ensure www-data owns all Nextcloud files
- OPcache/APCu not loading: check php -m and phpinfo(); restart php8.3-fpm
# Quick health check
sudo -u www-data php /var/www/nextcloud/occ status
sudo -u www-data php /var/www/nextcloud/occ check
Alternative: Nextcloud Snap (quick install)
Snap is the fastest route but less flexible for tuning, custom PHP modules, or external database engines.
sudo apt -y install snapd
sudo snap install nextcloud
# Set domain and enable HTTPS
sudo nextcloud.manual-install admin StrongAdminPassword
sudo nextcloud.enable-https lets-encrypt
For production environments where you need deep control (Redis, PHP tuning, advanced Nginx rules), the manual install above is preferred.
Why host Nextcloud with YouStable
As a managed hosting provider, YouStable offers optimized Ubuntu 24.04 VPS with NVMe storage, free SSL, DDoS protection, and expert assistance setting up Nextcloud, Redis, and backups. If you want a hands off, production ready deployment with 24×7 support, our team can provision and tune this stack for your workload.
FAQs – Install Nextcloud on Ubuntu 24.04 LTS
1. Is Apache or Nginx better for Nextcloud on Ubuntu 24.04?
Both work well. Apache is simpler and integrates nicely with Certbot. Nginx offers lower memory use and excellent performance under high concurrency. For small to medium teams, Apache is perfect; for heavy traffic or large deployments, Nginx is often the better choice.
2. Should I use MariaDB or PostgreSQL for Nextcloud?
MariaDB is easy to start with and fully supported. PostgreSQL tends to scale better and can offer improved query performance as your instance grows. If you anticipate thousands of users or heavy app usage, choose PostgreSQL; otherwise MariaDB is perfectly fine.
3. How do I increase the Nextcloud upload size limit?
Adjust PHP and web server limits: set upload_max_filesize and post_max_size in /etc/php/8.3/fpm/php.ini (e.g., 2G), and for Nginx set client_max_body_size in the server block. Restart PHP-FPM and reload your web server. Also ensure any proxy or CDN respects the larger limit.
4. Can I move the Nextcloud data directory after install?
Yes. Put the site in maintenance mode, move data to the new path with preserved ownership (www-data), update the datadirectory path in config.php, adjust AppArmor if enabled, then disable maintenance mode. Always back up before relocating the data directory.
5. Is the Snap package good for production in 2026?
Snap is stable and convenient, ideal for quick pilots or small personal setups. For production environments needing fine grained PHP, Nginx, Redis, and database optimizations, or custom modules, the manual LAMP/LEMP installation provides better control and performance.
You now have a secure, tuned deployment of Nextcloud on Ubuntu 24.04 LTS. Maintain it with regular OS updates, database backups, and Nextcloud upgrades via occ or the web updater. For managed infrastructure and expert help at every step, YouStable is ready to assist.