Introduction
In this guide, you’ll learn how to install a Nextcloud server on Ubuntu — a reliable and secure way to host your own private cloud. Whether you’re storing files, sharing documents, or syncing data across devices, Nextcloud gives you full control, and Ubuntu is a solid choice for hosting it.
This tutorial uses plain language and is perfect for beginners or anyone looking for a smooth installation process.
What is Nextcloud and Why Use It?
Nextcloud is an open-source file-sharing and collaboration platform that lets you run your own cloud storage server — similar to Dropbox or Google Drive, but with full data privacy.
Why choose Nextcloud on Ubuntu?
- Complete control over your data
- No monthly fees
- Strong community and regular updates
- Runs great on Ubuntu, one of the most popular Linux distributions
System Requirements
Before starting, make sure your Ubuntu server meets the following requirements:
- Ubuntu 22.04 LTS (or Ubuntu 20.04)
- A non-root user with sudo privileges
- At least 2 GB of RAM (4 GB recommended)
- Minimum 2 CPU cores
- 20+ GB disk space (depending on your use)
- Internet connection
- Domain name (optional but recommended)
Step 1: Update Your Ubuntu Server
First, log into your server and make sure all packages are up to date:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Packages
Install software that Nextcloud needs to run:
sudo apt install apache2 mysql-server libapache2-mod-php php php-mysql php-gd php-xml php-mbstring php-curl php-zip php-intl php-bcmath php-imagick unzip -y
This installs:
- Apache (web server)
- MySQL (database)
- PHP (scripting language) with all needed extensions
Step 3: Configure the MySQL Database for Nextcloud
Log in to MySQL:
sudo mysql
Then, create a database and user:
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace ‘yourpassword’ with a strong password.
Step 4: Download and Install Nextcloud
Go to the official Nextcloud download page or use the command below to get the latest version:
cd /tmp
wget https://download.nextcloud.com/server/releases/latest.zip
unzip latest.zip
sudo mv nextcloud /var/www/html/
Step 5: Set the Right Permissions
sudo chown -R www-data:www-data /var/www/html/nextcloud
sudo chmod -R 755 /var/www/html/nextcloud
These commands make sure that Apache can read and write to the Nextcloud directory.
Step 6: Create Apache Virtual Host File
Create a new config file for Nextcloud:
sudo nano /etc/apache2/sites-available/nextcloud.conf
Paste the following:
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html/nextcloud
ServerName yourdomain.com
<Directory /var/www/html/nextcloud/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>
Then enable the config and modules:
sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime
sudo systemctl restart apache2
Step 7: (Optional) Secure Your Site with HTTPS (Let’s Encrypt)
Use Certbot to add a free SSL certificate:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com
Follow the prompts and your site will now be accessible via HTTPS.
Step 8: Complete the Installation via Web Browser
Open your browser and go to:
http://yourdomain.com
or
http://your_server_ip/nextcloud
You’ll see the Nextcloud setup screen.
Enter:
- Admin username and password
- Database user: nextclouduser
- Database password: the one you created
- Database name: nextcloud
- Host: localhost
Click Finish Setup — that’s it!
Post-Installation Tips
- Enable recommended apps like Contacts, Calendar, and Collabora Online.
- Add trusted domains to config.php if using a custom domain.
- Regularly update your server and Nextcloud.
- Set up cron jobs for background tasks:
sudo crontab -u www-data -e
Add:
*/5 * * * * php -f /var/www/html/nextcloud/cron.php
Conclusion
Installing a Nextcloud server on Ubuntu gives you full control over your data in a secure, cost-effective way. With just a few commands, you’ve set up your own private cloud — no subscriptions, no third-party access, and lots of flexibility.
Ready to enjoy the freedom of open-source storage? Go ahead and start uploading your files, sharing folders, or even collaborating in real-time with built-in apps.
Take back control of your digital life today.