Install Nextcloud on Ubuntu 22.04

This guide will quickly show you how to install Nextcloud on Ubuntu 22.04. Nextcloud is an open-source file sharing server. It stores files in a centralized location and allows you to manage utilities like Maps, Calendars, Word Processing and so on. You are in control of the security of the data stored on the Nextcloud server.

Nextcloud offers dependable self-hosted cloud services and appears to be a viable alternative to platforms like Box and Dropbox.

Install Nextcloud on Ubuntu 22.04

Before you install Nextcloud on Ubuntu 22.04, you need to install:

  • PHP 7
  • Apache/Nginx/Lamp web-server
  • MySQL/MariaDB Database server

I will show you how to use Apache server for installation because it is already installed on Ubuntu 22.04.

Step 1: Update system packages

Update the system packages to avoid dependency issues by executing the command;

sudo apt update && sudo apt upgrade -y

Step 2: Install PHP and required modules

Installing PHP in Ubuntu 22.04 installs PHP 8 and above. However, Nextcloud does not work with PHP version 8.

Perform some workaround tweaks so that you can install PHP 7.4

sudo apt-cache policy php
add-apt-repository ppa:ondrej/php --yes &> /dev/null
sed -i 's/jammy/focal/' /etc/apt/sources.list.d/ondrej-ubuntu-php-jammy.list
sudo apt update
sudo apt install php7.4

If you get an error such as the ones below,

itnixpro@itnixpro:~$ sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libzip4 : Depends: libssl1.1 (>= 1.1.0) but it is not installable
 php7.4-cli : Depends: libssl1.1 (>= 1.1.0) but it is not installable
 php7.4-common : Depends: libssl1.1 (>= 1.1.0) but it is not installable
 php7.4-intl : Depends: libicu66 (>= 66.1-1~) but it is not installable
E: Unable to correct problems, you have held broken packages.

Install missing dependencies.

First download and install libssl:

wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb

Then download and install libicu:

wget http://archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu66_66.1-2ubuntu2_amd64.deb
sudo dpkg -i libicu66_66.1-2ubuntu2_amd64.deb

Now install PHP required modules:

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

Change the PHP parameters by editing the php.ini file.

sudo gedit /etc/php/*/apache2/php.ini

Press CTRL+F to find the lines below, update as below save file.

date.timezone = Africa/Nairobi
memory_limit = 512M
max_execution_time = 60

Step 3: Install MariaDB Server

Install MariaDB which is a better version of MySQL database.

sudo apt install mariadb-server -y

Create Nextcloud database

Now create a database for Nextcloud.

sudo mysql -u root -p

Enter the lines one after another while hitting enter. I will use username as itnixpro and password as IT-nix.pro2022! Make sure you use a strong password and change these details to match your liking.

CREATE DATABASE nextcloud;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'itnixpro'@'localhost' IDENTIFIED BY 'IT-nix.pro2022!';
FLUSH PRIVILEGES;
EXIT;

Now that prerequisites are met, Install Nextcloud on Ubuntu 22.04.

Step 4: Install Nextcloud on Ubuntu 22.04

Download the latest version of Nextcloud using wget command;

wget https://download.nextcloud.com/server/releases/latest-23.zip

Extract the Nextcloud archive using the unzip command to /var/www/html/ directory.

sudo unzip latest-23.zip -d /var/www/html/

Grant the nextcloud directory ownership and read and write permissions:

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

Step 5: Configure Apache Webserver

Since Apache server is already installed in Ubuntu 22.04, proceed with configuration.

Create Apache configuration file for Nextcloud.

sudo gedit /etc/apache2/sites-available/nextcloud.conf

Add the following lines, save the file and close it.

<VirtualHost *:80>
        DocumentRoot "/var/www/html/nextcloud"
        ServerName nextcloud.itnixpro.com

        ErrorLog ${APACHE_LOG_DIR}/nextcloud.error
        CustomLog ${APACHE_LOG_DIR}/nextcloud.access combined

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

           <IfModule mod_dav.c>
               Dav off
           </IfModule>

        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
        Satisfy Any

       </Directory>
</VirtualHost>

Reload Apache server;

systemctl reload apache2

Enable the Nextcloud virtual host file.

sudo a2ensite nextcloud.conf

Enable required Apache modules.

sudo a2enmod rewrite dir mime env headers

Reload Apache webserver again.

sudo systemctl reload apache2

Step 6: Finalize Nextcloud Setup from Browser

Open the link http://127.0.0.1/nextcloud/ (enter your IP address if you provided it at nextcloud.conf)

Create an admin account.

Specify the data directory. This has to be the data directory you granted ownership.

Enter the database connection details you created in MariaDB

Now install Nextcloud on Ubuntu 22.04 by clicking Install

Install Nextcloud on Ubuntu 22.04

Wait for installation to complete.

Install recommended apps if need be.

Continue with few on boarding steps until you reach the screen below. Now click on Start using Nextcloud.

The Nextcloud dashboard loads;

Conclusion

Your patience has paid off because you have successfully managed to install Nextcloud on Ubuntu 22.04. Find more on Nextcloud Documentation

More interesting tutorials

Install Bacula Server with MariaDB on Ubuntu 22.04

Install BackupPC on Ubuntu 22.04

Install and Configure Postfix as Send-Only SMTP on Ubuntu 22.04

Android Developer | Linux | Technical Writer | Backend Developer

Leave a Comment