How to install and configure NextCloud on OpenSUSE Leap 15.3 and LEMP

In this guide, we are going to set up NextCloud on a OpenSUSE Leap 15.3 server hosted with Nginx, Mariadb and PHP (LEMP stack). We will be using Mariadb 10 and PHP 7.4 for this guide.

Nextcloud is an Open Source suite of client-server software for creating and using file hosting services. It is a  a free self-hosted cloud storage solution similar to Dropbox, Google Drive, etc. With Nextcloud, you don’t have to worry about the pricey alternatives and since you will host your own files, you don’t have to worry about privacy or someone collecting your data.

NextCloud can be installed on a private home server or a virtual private server in the cloud. Files can then be uploaded and then synced to a local desktop, laptop or even a smartphone. This way you have full control of your data.

# Features of NextCloud

  • NextCloud has sync clients for Linux, Mac OS, Windows, Android and IOS
  • End to end encryption – files are encrypted while being uploaded to the server
  • NextCloud is free and Open Source
  • Can be integrated with an online office suite (Collobora, OnlyOffice) so you can create and edit your doc, ppt, xls files directly from NextCloud.
  • The app store contains hundreds of apps to extend functionality (like calendar app, notes-taking app, video conferencing app, etc).

# Prerequisites

To follow along this guide, ensure that you have:

  • An up to date OpenSUSE Leap Server
  • Internet access from the server
  • Root access from the server or user with sudo access

# Table of Content

  1. Ensure that the server packages are up to date
  2. Installing Mariadb 10 in OpenSUSE Leap 15.3
  3. Creating mysql user for NextCloud
  4. Installing PHP in OpenSUSE Leap 15.3
  5. Installing Nginx in OpenSUSE Leap 15.3
  6. Download and configure Nextcloud
  7. Configure Nginx to serve NextCloud from a virtual host
  8. Update PHP Configuration
  9. Accessing Nextcloud from the web url

# 1. Ensure that the server packages are up to date

Let us make sure that our server packages are up to date with this command:

sudo zypper refresh
sudo zypper update -y

While at it, let us also install some dependencies that we will require

sudo zypper install -y unzip vim

# 2. Installing Mariadb in OpenSUSE Leap 15.3

Mariadb is a popular Opensource relational management system. It is available in the default repositories as mariadb.

Install it with this command:

sudo zypper install -y mariadb

Once mariadb is installed, you can confirm the details using this command:

~> zypper info mariadb
Loading repository data...
Reading installed packages...


Information for package mariadb:
--------------------------------
Repository     : Update repository with updates from SUSE Linux Enterprise 15
Name           : mariadb
Version        : 10.5.13-3.12.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 138.2 MiB
Installed      : Yes
Status         : up-to-date
Source package : mariadb-10.5.13-3.12.1.src
Summary        : Server part of MariaDB
Description    :
    MariaDB is an open-source, multi-threaded, relational database management
    system. It's a backward compatible, drop-in replacement branch of the
    MySQL Community Server.

    This package only contains the server-side programs.

The Service will not be started by default. Start with this command:

sudo systemctl start mariadb

Confirm the status with this command:

~> sudo systemctl status mariadb
● mariadb.service - MariaDB database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
     Active: active (running) since Mon 2021-12-20 09:39:18 UTC; 55s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 27806 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper install (code=exited, status=0/SUCCESS)
    Process: 27854 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper upgrade (code=exited, status=0/SUCCESS)
   Main PID: 27860 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 17 (limit: 4587)
     CGroup: /system.slice/mariadb.service
             └─27860 /usr/sbin/mysqld --defaults-file=/etc/my.cnf --user=mysql

Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: See the MariaDB Knowledgebase at https://mariadb.com/kb or the
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: MySQL manual for more instructions.
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: Please report any problems at https://mariadb.org/jira
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: The latest information about MariaDB is available at https://mariadb.org/.
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: You can find additional information about the MySQL part at:
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: https://dev.mysql.com
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: Consider joining MariaDB's strong and vibrant community:
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: https://mariadb.org/get-involved/
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27860]: 2021-12-20  9:39:18 0 [Note] /usr/sbin/mysqld (mysqld 10.5.13-MariaDB) starting as process 27860 ...
Dec 20 09:39:18 ip-10-2-40-44 systemd[1]: Started MariaDB database server.

To ensure that mariadb starts on boot, enable it with this systemd command:

sudo systemctl enable mariadb

Once the mysql service is running, you need to secure it. Mysql provides a commandline utility that will do that:

sudo mysql_secure_installation

The above command will take you throuh prompts to secure and set a root password for the mysql instance.

Check more info on How to install and Configure Mariadb 10 in OpenSUSE Leap 15.3.

# 3. Creating mysql user for NextCloud

It is always recommended to have a dedicated user for each app that connects to the DB. Check out this guide on managing mysql permissions here. We will set up a database, user and password to be used by nextcloud:

Connect to mysql server:

mysql -u root -p

After Supplying your password, enter the following to the mysql prompt:

create database nextcloud;
create user 'nextcloud_user'@'%' identified by 'S0mStrongPa$$word';
grant all privileges on nextcloud.* to 'nextcloud_user'@'%';

Now that we have configured our mysql connection, lets go to the next section where we install and configure PHP and Nginx.

# 4. Installing PHP 7.4 in OpenSUSE Leap 15.3

NextCloud works fine with PHP 7.4. This version is available in the default OpenSUSE repos.

Then install php and dependancies

sudo zypper install -y \
  php \
  php-gd \
  php-curl \
  php-zip \
  php-dom \
  php-xml \
  php-simplexml \
  php-mbstring \
  php-intl \
  php-json \
  php-fpm

For more info on setting up PHP and Nginx, check out this guide on How to Install and set up PHP and Nginx (LEMP) on OpenSUSE Leap 15.3.

# 5. Installing Nginx in OpenSUSE Leap 15.3

Next, let us install Nginx in our system. Use this command to install nginx

sudo zypper install -y nginx

Nginx will be not be started by default. Start with this command:

sudo systemctl start nginx

Check the status using this command:

~> sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
     Active: active (running) since Mon 2021-12-20 09:55:29 UTC; 30s ago
    Process: 29331 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
   Main PID: 29332 (nginx)
      Tasks: 2 (limit: 4587)
     CGroup: /system.slice/nginx.service
             ├─29332 nginx: master process /usr/sbin/nginx -g daemon off;
             └─29333 nginx: worker process

Dec 20 09:55:29 ip-10-2-40-44 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 20 09:55:29 ip-10-2-40-44 nginx[29331]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 20 09:55:29 ip-10-2-40-44 nginx[29331]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Dec 20 09:55:29 ip-10-2-40-44 systemd[1]: Started The nginx HTTP and reverse proxy server.

Active: active (running) indicate that the service is now up and running.

To enable the service on boot, use this command:

sudo systemctl enable nginx

# 6. Download and configure Nextcloud

Now that we have successfully configured the LEMP server in our system, let us download and set up NextCloud. You can get the latest version of NextCloud from the NextCloud installation page. Use this command to download the server NextCloud:

cd /tmp
curl -LO https://download.nextcloud.com/server/releases/nextcloud-23.0.0.zip

Now let us change into a directory path to serve NextCloud in /var/www then extract the downloaded file there:

cd /var/www
sudo unzip /tmp/nextcloud-23.0.0.zip
sudo chown -R $USER:$GROUP nextcloud
sudo chmod -R 755 nextcloud

Nextcloud required a directory to keep its data. So create a data directory and set the proper permissions on nextcloud directory

sudo mkdir -p /var/nextcloud/data
sudo chown -R $USER:$GROUP /var/nextcloud
sudo chmod -R 755 /var/nextcloud

# 7. Configure Nginx to serve NextCloud from a virtual host

We managed to download the NextCloud content to /var/www/nextcloud. The next bit it to set up Nginx to serve it.

Let’s create virtual site in the directory that nginx serves content here /etc/nginx/conf.d:

sudo vim /etc/nginx/conf.d/nextcloud.conf

Add the following content:

server {
    listen 80;

    server_name nextcloud.citizix.com;
    root /var/www/nextcloud;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Once the abve changes have been made, we need to restart the nginx server and the php-fom server. Use these commands in the terminal to achieve that.

sudo systemctl restart php7.4-fpm nginx

# Accessing Nextcloud from the web url

Then head to your set domain, http://nextcloud.citizix.com/nextcloud for me. You will be asked to create the user account. Ente the username and password to be using for the new user:

Create a Nextcloud account

Then enter the Database Details:

NextCloud Enter Database Details

After that Click Finish. You will be redirected to the login page where you will use the details for the created user to login. On Successful login you will get the Dashboard.

# Conclusion

In this guide, we managed to set up LEMP on OpenSUSE Leap 15.3 to serve Next cloud.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy