Use this guide as an implementation reference. Validate commands, policies and version-specific behaviour in a lab before applying changes to production systems.
1. Choose the deployment method
This guide uses the official Nextcloud server archive on Ubuntu 24.04 LTS with Apache and MariaDB. The current Nextcloud administration manual recommends the archive-based installation for a conventional Linux server. Check the current Nextcloud system requirements before selecting PHP and database versions; Nextcloud 35 supports newer PHP runtimes and MariaDB releases than older tutorials.
Plan a separate data volume for user files, configure DNS and reserve enough storage for versioning, trash, previews and backups.
2. Install Apache, MariaDB and PHP extensions
sudo apt update && sudo apt full-upgrade -y\nsudo apt install -y apache2 mariadb-server libapache2-mod-php \\\n php-gd php-mysql php-curl php-mbstring php-intl php-gmp \\\n php-xml php-imagick php-zip php-bcmath php-apcu \\\n php-cli php-common php-bz2 php-redis redis-server unzip curl\nsudo systemctl enable --now apache2 mariadb redis-serverConfirm the PHP version installed by Ubuntu and compare it with the exact Nextcloud release requirements. Install any additional modules listed in the Nextcloud documentation.
3. Create the database and account
sudo mariadbCREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;\nCREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'REPLACE_WITH_STRONG_PASSWORD';\nGRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;Use a unique database password and keep MariaDB local. Do not use the database root account in the Nextcloud application.
4. Download and deploy Nextcloud
Download the latest stable server archive and its checksum/signature from the official Nextcloud download page. Verify the archive before extracting it.
cd /tmp\n# Download the current stable server archive from nextcloud.com/install\nsudo tar -xjf latest.tar.bz2 -C /var/www/\nsudo mkdir -p /var/ncdata\nsudo chown -R www-data:www-data /var/www/nextcloud /var/ncdata\nsudo chmod 750 /var/ncdataKeep the data directory outside the web root. If user files are stored on a separate disk, mount it persistently using its UUID in /etc/fstab before completing the setup.
5. Configure Apache
sudo a2enmod rewrite headers env dir mime setenvif\nsudo nano /etc/apache2/sites-available/nextcloud.conf<VirtualHost *:80>\n ServerName cloud.example.com\n DocumentRoot /var/www/nextcloud\n <Directory /var/www/nextcloud/>\n Require all granted\n AllowOverride All\n Options FollowSymLinks MultiViews\n </Directory>\n ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log\n CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined\n</VirtualHost>sudo a2ensite nextcloud.conf\nsudo a2dissite 000-default.conf\nsudo apache2ctl configtest\nsudo systemctl reload apache26. Complete the web installation
Open http://cloud.example.com. Create the Nextcloud administrator, set the data directory to /var/ncdata, and enter the database name, database user and password. Choose MariaDB/MySQL as the database backend. Complete setup and sign in.
After installation, add the hostname to Nextcloud's trusted_domains configuration and verify the data directory permissions.
7. Enable HTTPS, Redis locking and background jobs
Issue a TLS certificate after DNS is pointed to the server:
sudo apt install -y certbot python3-certbot-apache\nsudo certbot --apache -d cloud.example.comConfigure Redis for transactional file locking and local caching according to the Nextcloud admin manual. Set the background job mode to Cron in the Administration settings and schedule cron.php:
sudo crontab -u www-data -e*/5 * * * * php -f /var/www/nextcloud/cron.phpUse the PHP CLI binary matching the web runtime. Configure trusted proxy addresses only if the server is behind a reverse proxy.
8. Post-install checks and hardening
Run the built-in command-line status check and review the Administration overview for warnings. Configure SMTP, upload limits, preview generation, update notifications and a maintenance window. Restrict access to the admin interface, enable MFA, and keep apps and server releases updated.
sudo -u www-data php /var/www/nextcloud/occ status\nsudo -u www-data php /var/www/nextcloud/occ maintenance:repairBack up the database, data directory, configuration directory and installed apps. For consistent backups, enable maintenance mode or use the documented snapshot/backup procedure.
Official references
Conclusion
A reliable Nextcloud server needs more than file upload functionality: use a supported PHP/database combination, private data storage, Redis locking, cron, HTTPS and tested backups to protect user data.
