Installing Nextcloud
Nextcloud can handle all your document storage and sharing requirements. Who needs Dropbox?
There’s a number of ways to install Nextcloud, including the use of à la mode container systems such as Docker or Snap. These are easy to set up, but integrating them with CODE (and otherwise tweaking their internals) is more involved, so we’ll roughly follow the official guidance at https:// docs.nextcloud.com/server/latest/admin_manual/ installation/example_ubuntu.html. Use SSH to log in to your Ubuntu server (it should also work on Debian) and update, upgrade and install the packages with:
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install apache2 mariadb-server libapache2mod-php php-gd php-mysql php-curl php-mbstring
php-intl php-gmp php-bcmath php-xml php-imagick php-zip
You can copy and paste the package list (and subsequent code screeds) from the documentation linked above to avoid tedium. Now we’ll set up our database server, using the freshly installed
MariaDB. This is technically optional, because Nextcloud can use the flat-file database SQLite. This isn’t very performant, though, even with a single user, as the Nextcloud app is highly concurrent and SQLite only handles a single write operation at a time. Start the MariaDB console with $ sudo mysql .
MariaDB is command-compatible with
MySQL, but less Oracle-ey. Next we’ll set up a database and user for Nextcloud (using a wide character set for extra emoji and language support). Replace password with a suitable password:
CREATE USER ‘nextcloud’@’localhost’ IDENTIFIED BY
‘password’;
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_ general_ci;
GRANT ALL PRIVILEGES ON nextcloud.* TO ‘nextcloud’@’localhost’; FLUSH PRIVILEGES; quit;
Now we’ll download the latest release of Nextcloud, extract the tarball, put the contents in Apache’s document root and set the appropriate permissions:
$ wget https://download.nextcloud.com/server/
releases/latest.tar.bz2
$ tar xvjf latest.tar.bz2
$ sudo mv nextcloud /var/www
$ sudo chown -R www-data:www-data /var/www/
nextcloud
It’s good practice to check the MD5 checksums and PGP signatures of the tarball, but we’re short of space, so do check the docs for more details. Meanwhile, we’ve got a web server to configure. Run:
$ sudo nano /etc/apache2/sites-available/nextcloud.conf
Now populate the configuration file as follows:
Alias /nextcloud “/var/www/nextcloud/”
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
Dav off
It’s recommended (as we’ll do later) to run CODE on a subdomain, such as code.example.org. We’ve set up Nextcloud to run in a subdirectory, example.org/ nextcloud in the above, for simplicity. This also allows users without domain names to follow. It’s easy to run Nextcloud as a subdomain (such as cloud.example.org)
instead, check the docs (https://docs.nextcloud.com/ server/latest/admin_manual/installation/source_ installation.html). Activate our new website with:
$ sudo a2ensite nextcloud.conf
We also need additional modules for Nextcloud to function correctly (some are enabled on Ubuntu 22.04):
$ sudo a2enmod rewrite headers env dir mime
We’re tantalisingly close to running Nextcloud for the first time. Restart Apache to pick up our changes:
$ sudo systemctl restart apache2
Now you should be able to access Nextcloud’s install script in a browser, by navigating to http://[ip address]/nextcloud (replacing with the server’s IP) or whatever domain you set it up on. Nextcloud requires an admin account, and to know the SQL database, user and password we set up. Once you’ve inputted all that, hit Install. This is a great time for a cup of tea.
You’re invited to install some Nextcloud apps (including Nextcloud Office). We’ll skip this for now; they can be added later. After closing the Nextcloud Hub welcome animation, you’re presented with some example documents. We don’t yet have the capability to view Microsoft DOCX files (or indeed LibreOffice
files) in the browser yet, so don’t get too excited.
Before you go any further, we strongly recommend setting up HTTPS encryption if you’re running Nextcloud on an internet-facing machine. This is easy to do with Let’s Encrypt’s Certbot tool, if you have a domain name already pointing at your Nextcloud instance. Install Certbot with:
$ sudo apt install python3-certbot-apache
Then, where example.domain.org (it might be a toplevel domain like example.org) is a domain under your control, with A records pointing at your server, run:
$ sudo certbot --apache -d example.domain.org
Follow the prompts and Certbot verifies that DNS records are all in order and if so adds a new site (called
nextcloud-le.conf) to the Apache config. You’re asked if you want to forward HTTP traffic to this site, which is a good idea.
Make sure that the certificate’s CommonName field matches Apache’s ServerName directive, and that both are set to the domain you want to access Nextcloud on, otherwise you will get errors.
It’s also possible to use the bundled self-signed certificate (which will result in browser warnings) if you don’t want to pay for domain registrations. This is fine for testing locally, and is achieved with:
$ sudo a2enmod ssl
$ sudo a2ensite default-ssl
$ sudo systemctl reload apache2
You can now access your site at https:// [ip-address]/nextcloud, once you click through the foretold security risk warnings. You need your certificate to be signed by a reputable certificate authority to get rid of these warnings, otherwise anyone could pretend to be Google.com, for example.
From the top-right menu, select Administration Settings. You’ll see some setup and security warnings. Ubuntu by default sets a low 128MB memory limit for PHP. Nextcloud is quite a memory-hungry beast and recommends at least 512MB. To change this, open the relevant PHP configuration file with:
$ sudo nano /etc/php/8.1/apache2/php.ini
Search (Ctrl+w) for memory_limit and change it to
512M . You may be tempted to set an even higher limit, but this might be a bad idea if you’re on, for example, a cheap VPS with little memory. Apache and MariaDB can also be memory-hungry under pressure, so you probably want your server to have at least 2GB to run Nextcloud (with the recommended memory limit set) comfortably. In our experience running with a 1GB VPS, the database is usually the first casualty under memory pressure. This results in Apache serving a rather unhelpful 500 – Internal Server Error message. Reload the Apache configuration for changes to take effect.
If you have a valid HTTPS certificate, follow the guidance for setting up HSTS by clicking Security Tips. Any other issues the diagnostic picks up are likely minor, and they helpfully all include a link to address them. See the box (below) if you want to get rid of the memcache warning and speed things up a bit.
It’s worth spending some time uploading test files and perhaps installing some app recommendations from the notification bell. You might at this stage want to add a regular (non-admin) user, too. Oh, and always check the logs – they’re in the hamburger menu that opens from the left, under the Administration heading.