KB0450305 – Installing Nextcloud on Ubuntu

Last modified: April 26, 2021
You are here:
  • KB Home
  • KB0450305 – Installing Nextcloud on Ubuntu
Estimated reading time: 2 min

Installing Nextcloud on Ubuntu 20.04LTS

Scope/Description:

This guide will run through the process of installing Nextcloud on Ubuntu. The guide will include installing all required packages, configuring a database for Nextcloud to use, and bringing the Nextcloud installation up to begin using.

Prerequisites:

This guide assumes you are running the Ubuntu 20.04LTS image shipped with a 45Drives Storinator product or you have completed the knowledgebase article “KB045290 – Configuring Fresh Install of Ubuntu 20.04LTS for Houston UI” which makes some changes as the default manager for things like network and firewall.

Steps:

  • Install all required packages (apache,sql,mariadb,php,etc.)
<root@mitchubu> apt install apache2 mariadb-server libapache2-mod-php7.4 -y
<root@mitchubu> apt install php7.4-gd php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl -y
<root@mitchubu> apt install php7.4-gmp php7.4-bcmath php-imagick php7.4-xml php7.4-zip -y
  • Next, start SQL and create a new database for nextcloud.
<root@mitchubu> /etc/init.d/mysql start
<root@mitchubu> mysql -uroot -p
  • From here, the MariaDB prompt will appear. Database syntax is extremely fussy, so ensure to make no mistakes when running the next few commands. Remember the username and password as you will be required to enter this information in the web UI in order to complete installation.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
quit;
  • Download the latest version of Nextcloud at the Nextcloud Download Page
  • Go to Download Nextcloud Server > Download  > Archive file for server owners and copy the link for the tar.bz2 install to pull down on your Ubuntu machine. Replace the X’s with the most up-to-date download link.
<root@mitchubu> wget https://download.nextcloud.com/server/releases/nextcloud-XX.X.X.tar.bz2
  • Extract the contents of the tar archive.
<root@mitchubu> tar -xjvf nextcloud-xx.x.x.tar.bz2
  • There will now be a nextcloud directory extracted. Copy this to the root of your apache directory, and then give ownership of this directory to apache
<root@mitchubu> cp -r nextcloud/ /var/www
<root@mitchubu> chown -R www-data:www-data /var/www/nextcloud
  • Configure Apache to host Nextcloud. First, create a nextcloud.conf file in your apache sites-available directory, and then copy the following configuration settings into that file.
<root@mitchubu> vim /etc/apache2/sites-available/nextcloud.conf

Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews

  <IfModule mod_dav.c>
    Dav off
  </IfModule>
</Directory>
  • Next, We will enable the Nextcloud configuration as well as some additional Apache configurations for Nextcloud to work correctly.
<root@mitchubu> a2ensite nextcloud.conf
<root@mitchubu> a2enmod rewrite
<root@mitchubu> a2enmod headers
<root@mitchubu> a2enmod env
<root@mitchubu> a2enmod dir
<root@mitchubu> a2enmod mime
<root@mitchubu> systemctl restart apache2

  • Configuring SSL

Note: If this Nextcloud configuration is to be used over the internet, it is highly recommended to use SSL to encrypt all traffic between the Nextcloud server and the clients. The most secure way to do this is to purchase a domain, use a certificate authority to purchase a certificate, and enable it on your Nextcloud server. The next best thing if you have a domain you can use Let’s Encrypt to issue a free certificate. This only lasts 3 months, but it can be configured to be auto-renewed. This guide is going to show how to use a self-signed certificate. When accessing the Nextcloud server over the internet, your web browser will still see this as insecure, because the browser has no way of knowing if this certificate is legitimate. However, it does at least secure the traffic between client and server and is secure.

  • Next, enable ssl and use the default-ssl certificate. Finally, reload apache.
<root@mitchubu> a2enmod ssl
<root@mitchubu> a2ensite default-ssl
<root@mitchubu> systemctl reload apache2
  • Finally, open port 80 and 443 (http,https) on the firewall to allow nextcloud traffic to and from the server
<root@mitchubu> firewall-cmd --permanent --zone=public --add-port=80/tcp
<root@mitchubu> firewall-cmd --permanent --zone=public --add-port=443/tcp
<root@mitchubu> firewall-cmd --reload
  •  Configuration through the CLI is complete for now. Open a web browser and navigate to the nextcloud install: https://x.x.x.x/nextcloud
  • This brings you to the Nextcloud configuration page. First, create a new admin user/password to manage nextcloud. Next, enter the database user/password and database name information you created in the previous steps

  • Decide if you want to install their recommended apps or not, and finally click ‘Finish setup”
  • Base Nextcloud installation is complete.

Verification:

Navigate back to https://x.x.x.x/nextcloud to be greeted by the Nextcloud login page.

Troubleshooting:

Was this article helpful?
Dislike 0
Views: 17
Unboxing Racking Storage Drives Cable Setup Power UPS Sizing Remote Access