If you’re looking to break free from Google Drive, Dropbox, or OneDrive, Nextcloud is one of the best self-hosted alternatives available. It gives you complete control over your files, calendar, contacts, and more—all running on your own hardware.
In this guide, we’ll walk through installing Nextcloud on Ubuntu Server from start to finish.
What is Nextcloud?
Nextcloud is an open-source, self-hosted file sync and collaboration platform. Think of it as your own private cloud that you fully control. Key features include:
- File sync across all your devices
- Calendar and contacts sync
- Collaborative document editing
- Photo and video backup
- Extensible with apps (notes, tasks, music, and more)
Prerequisites
Before we begin, you’ll need:
- A server running Ubuntu 22.04 LTS or newer
- Root or sudo access
- A domain name (optional but recommended for SSL)
- At least 2GB RAM and 20GB storage
For this guide, we’ll use the LAMP stack (Linux, Apache, MySQL, PHP).
Step 1: Update Your System
Always start with a fresh system update:
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache Web Server
Install Apache and enable required modules:
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
Enable the modules Nextcloud needs:
sudo a2enmod rewrite headers env dir mime ssl
sudo systemctl restart apache2
Step 3: Install MariaDB Database
MariaDB is a reliable, open-source database that works great with Nextcloud:
sudo apt install mariadb-server -y
sudo systemctl enable mariadb
sudo mysql_secure_installation
During the secure installation:
- Set a root password
- Remove anonymous users: Yes
- Disallow root login remotely: Yes
- Remove test database: Yes
- Reload privileges: Yes
Now create the Nextcloud database:
sudo mysql -u root -p
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'YourStrongPassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace YourStrongPassword with a secure password.
Step 4: Install PHP and Required Extensions
Nextcloud requires PHP 8.1 or newer with several extensions:
sudo apt install php php-apcu php-bcmath php-cli php-common php-curl php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml php-redis libapache2-mod-php -y
Verify PHP is installed:
php -v
Step 5: Download and Install Nextcloud
Download the latest Nextcloud release:
cd /tmp
wget https://download.nextcloud.com/server/releases/latest.tar.bz2
Extract and move to the web directory:
sudo tar -xjf latest.tar.bz2
sudo mv nextcloud /var/www/html/
sudo chown -R www-data:www-data /var/www/html/nextcloud
sudo chmod -R 755 /var/www/html/nextcloud
Step 6: Configure Apache for Nextcloud
Create a virtual host configuration:
sudo nano /etc/apache2/sites-available/nextcloud.conf
Add this configuration (replace yourdomain.com with your actual domain):
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/nextcloud
ServerName yourdomain.com
<Directory /var/www/html/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>
Enable the site:
sudo a2ensite nextcloud.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2
Step 7: Complete Web Installation
Open your browser and navigate to http://your-server-ip/ or http://yourdomain.com/
You’ll see the Nextcloud setup wizard. Enter:
- Admin username and password of your choice
- Data folder: Leave default or change to a larger disk
- Database user:
nextclouduser - Database password: The password you created earlier
- Database name:
nextcloud - Database host:
localhost
Click Install and wait for the setup to complete.
Step 8: Configure PHP for Better Performance
Edit the PHP configuration:
sudo nano /etc/php/8.1/apache2/php.ini
Find and modify these values:
memory_limit = 512M
upload_max_filesize = 1G
post_max_size = 1G
max_execution_time = 300
date.timezone = America/New_York
Restart Apache:
sudo systemctl restart apache2
Step 9: Set Up SSL with Let’s Encrypt (Recommended)
For secure HTTPS access, install Certbot:
sudo apt install certbot python3-certbot-apache -y
Obtain and install a certificate:
sudo certbot --apache -d yourdomain.com
Follow the prompts to complete SSL setup. Certbot will automatically configure Apache and set up auto-renewal.
Step 10: Configure Nextcloud Cron Jobs
For better performance, set up a system cron instead of AJAX:
sudo crontab -u www-data -e
Add a cron job to run every 5 minutes. The format is:
MINUTE HOUR DAY MONTH WEEKDAY COMMAND
Add this line (runs every 5 minutes):
echo "*/5 * * * * php -f /var/www/html/nextcloud/cron.php" | sudo tee -a /var/spool/cron/crontabs/www-data
Or manually add: every 5 minutes, run the Nextcloud cron:
*/5 * * * * php -f /var/www/html/nextcloud/cron.php
Then, go to Settings > Administration > Basic settings and select Cron as the background job method.
Optimizing Nextcloud
Enable Memory Caching
Edit the Nextcloud config:
sudo nano /var/www/html/nextcloud/config/config.php
Add before the closing );:
'memcache.local' => '\OC\Memcache\APCu',
'default_phone_region' => 'US',
Install Redis for File Locking (Optional)
For better performance with multiple users:
sudo apt install redis-server php-redis -y
sudo systemctl enable redis-server
Add to config.php:
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
'host' => 'localhost',
'port' => 6379,
],
Installing Mobile and Desktop Apps
Nextcloud offers sync clients for all platforms:
- Desktop: nextcloud.com/install/#install-clients
- Android: Available on Google Play and F-Droid
- iOS: Available on the App Store
Troubleshooting Common Issues
“Access through untrusted domain”
Edit config.php and add your domain to the trusted domains array:
'trusted_domains' =>
array (
0 => 'localhost',
1 => 'yourdomain.com',
2 => 'your-server-ip',
),
File upload fails for large files
Check both PHP settings (upload_max_filesize, post_max_size) and Apache’s LimitRequestBody if configured.
Slow performance
- Enable APCu and Redis caching
- Increase PHP memory limit
- Use system cron instead of AJAX
Wrapping Up
You now have a fully functional Nextcloud instance running on Ubuntu! You’ve got:
- A complete file sync solution
- Database backend with MariaDB
- SSL encryption (if configured)
- Optimized PHP settings
From here, explore the Nextcloud app store to add calendars, contacts, notes, and more. You’re now in control of your own cloud.
Related guides:
Check out the official Nextcloud documentation.