How to Install Nextcloud on Ubuntu

There are many online file storage services such as Google Drive and Dropbox. However, these are run by third parties, which means that you often don’t have control over the data you’ve uploaded. Fortunately, there are many privacy-aware, open-source alternatives that you can host on your own server. One of them is Nextcloud, a PHP-backed application that allows you to access files over a web interface and WebDAV.

In this article, we’ll learn how to install Nextcloud on a server running Ubuntu.

Installing Nextcloud via Snap

Installing Nextcloud via Snap is extremely easy. Snap is a new packaging technology that allows developers to ship software with multiple dependencies as a single package. Unfortunately, this method uses up port 80 and at the time of this writing, you can’t change this. Moreover, this method won’t work with OpenVZ-based servers. In these cases, you should use the manual installation instructions below this section.

In the latest version of Ubuntu, Snap is installed by default. However, if it is not installed, run the following command:

sudo apt install snapd

The Snap package comes with its own, bundled version of Apache which runs on port 80. If you have an existing web server, you should first remove it before continuing.

Next, run the following command:

sudo snap install nextcloud

After installation has been completed, you may visit localhost in your browser. On the web page that opens, fill in the username and password to set up an administrator account.

Now, you’ll be logged in to Nextcloud. You can now upload files to your Nextcloud installation and change its settings from the admin panel.

The Snap package also include a number of CLI utilities. These commands need root permissions to work, so you should add sudo before each command when you run them.

  • With nextcloud.enable-https, you can configure the built-in Apache server to use HTTPS. You can use a custom certificate, or it can obtain one from Let’s Encrypt. To disable HTTPS, you should run nextcloud.disable-https.
  • nextcloud.mysqldump and nextcloud.mysql-client allows you to interact with the built-in MySQL server. You can retrieve and change the data stored in the database with these commands.
  • nextcloud.occ is the Snap version of Nextcloud’s occ tool.  You can manage users and settings with this tool.

Manually installing Nextcloud

Setting up the prerequisites

Here, we will install Nextcloud along with Apache and MySQL manually. You can install each of these components separately, or you can use the lamp-server task to install all of them at one go:

sudo apt install lamp-server^ php-zip php-mbstring php-dom php-gd php-curl

During the installation, you’ll get a prompt to set up a root password for MySQL. You might not get any visual feedback when you enter the password. Once you’ve entered the password, hit Enter to continue.

After this step, you should run mysql_secure_installation in order to make the MySQL installation more secure. The script will first offer to change your password. Since we’ve just set a password, answer no to this question by entering n. Then, the script will ask a few more questions, such as if it should remove anonymous users and disallow remote root logins. Answer yes to all of these questions by entering y.

In Apache, you should also enable the rewrite, env, headers, dir and mime modules. This is necessary for Nextcloud to work correctly.

sudo a2enmod rewrite headers env dir mime

Then restart Apache for the changes to take place:

sudo systemctl restart apache2

On older versions of Ubuntu, you should run this command instead:

sudo service apache2 restart

Configuring MySQL

The next step is to configure MySQL. First, you should log into MySQL with the root password:

mysql -u root -p

Now, you have to create a new database in which Nextcloud will store information. This can be done with:


Now, you should also create a new MySQL user which Nextcloud will use to access the database. We’ll name the user nextcloud and assign it a password of superstrongpassword:

CREATE USER [email protected] IDENTIFIED BY 'superstrongpassword';

Then, you should grant the newly made account with all permissions to the database:

GRANT ALL PRIVILEGES ON nextcloud . * TO [email protected];

Keep a note of the username and password that you’ve used here — you’ll need them in the next section.

Install Nextcloud

Next, head over to the Nextcloud downloads page and download the latest ZIP file with wget or curl. Depending on the current version, the URL will vary. Here, we’ve downloaded the ZIP file for version 12, which is the latest release at the time of this writing.


Then, unzip the downloaded file into your web directory. Typically, this would be in /var/www/html, although you can select another directory if your web directory is located elsewhere.

sudo unzip -d /var/www/html

This will create a directory named nextcloud inside /var/www/html. This will make Nextcloud available under http://<your_server_name>/nextcloud. If you want it to be available directly, you can move the contents of the nextcloud directory directly under /var/www/html.

After extracting the file, you have to set the owner of the extracted files to the Apache user, www-data:

sudo chown -R www-data: /var/www/html/nextcloud

After you have completed the above steps without any issues, open your browser and type http://<your_server_name>/nextcloud in the address field. You should see a setup screen like the one below.

Here, you should fill in the details of the Nextcloud administrator account that will be created. You can manage various aspects of Nextcloud from this account. The data folder setting controls the folder in which user’s files are saved in. The default is usually fine.

Next, fill in the details for the database. In our case, the database user and name will be nextcloud, and the password will be superstrongpassword.

Finally, click on the “Finish setup” button to complete installation. You’ll be logged into Nextcloud’s file management interface, which looks like this:

If you’ve run all these steps without problems, congratulations! Nextcloud has been successfully installed on your server. We recommend you to go through the Nextcloud Manual, which explains all the functionality available.


Nextcloud is a great alternative to proprietary services such as Google Drive and Dropbox. It also provides a set of apps which you can install to extend its functionality in various ways. There are also apps for iOS and Android which you can use to access your files on the go.

Now that you’ve set up Nextcloud, why not configure HTTPS so that your files are secure while in transit? Check out our guides on configuring HTTPS with Cloudflare and Let’s Encrypt to find out more.

If you liked this post, please share it 🙂

You may also like...