How to install Nextcloud on CentOS 8

Share on Social Media

Nextcloud is a private cloud storage software. In this article, you will learn how to install Nextcloud on CentOS 8. #centlinux #linux #nextcloud

What is Nextcloud? :

Nextcloud is a free and open source software for creating and using web based file hosting services. It is developed and maintained by Nextcloud GmbH Community and distributed under AGPLv3 license.

Nextcloud is written in PHP programming language, therefore, it requires a LEMP or LAMP server for deployment. Thus, users can access Nextcloud web interface via their favorite web browsers.

For synchronization of files, Desktop clients are also available for Windows, macOS, FreeBSD or Linux, whereas Mobile clients are available for iOS and Android devices.

Nextcloud is of modular design, therefore, its basic functionality can be extended with plugins.

The latest version of Nextcloud Server is 19, which was released on 3 June 2020.

In September 2016, Nextcloud, in cooperation with Western Digital Labs and Canonical (the company behind Ubuntu), released the Nextcloud Box. The Nextcloud box was based on a Raspberry Pi, running Ubuntu Core with Snappy; it was intended to serve as a reference device for other vendors. In June 2017, Western Digital shut down Western Digital Labs, which caused the production of the box to end.

Get a CanaKit Raspberry Pi 4 4GB Starter Kit – 4GB RAM by CanaKit at a reasonable price.

Nextcloud Features:

Core features of Nextcloud server are:

  • It uses conventional directory structures for file storage
  • User files are encrypted during transit
  • User and group administration
  • Users can create public URLs for sharing content
  • Logging of file-related actions

Nextcloud System Requirements:

Minimum system requirements for Nextcloud server are:

  • Memory – 512MB
  • Operating System – CentOS 8
  • Database – MariaDB 10.2 or later
  • Web Server – Apache 2.4 or Nginx
  • PHP Runtime – 7.2 or later

A complete list of recommended software for Nextcloud is available on their website.

Environment Specification:

We are using a minimal CentOS 8 virtual machine with following specification.

  • CPU – 3.4 Ghz (1 cores)
  • Memory – 1 GB
  • Storage – 40 GB
  • Operating System – CentOS Linux 8.2
  • Hostname – nextcloud-01.centlinux.com
  • IP Address – 192.168.116.206 /24

Update Linux Software Packages:

Connect with nextcloud-01.centlinux.com as root user by using a SSH client such as PuTTY.

Use dnf command to update software packages on your Linux operating system.

# dnf update -y

Install MariaDB on CentOS 8:

Nextcloud software requires a back-end database server to create its data repository.

SQLite is the default database for Nextcloud server, which is good for test environments.

Nextcloud also supports MySQL, MariaDB, Oracle 11g and PostgreSQL databases. But MySQL/MariaDB are the recommended databases for Next Cloud in production environments.

Therefore, you should install MariaDB server on your Linux operating system.

# dnf install -y mariadb-server

Enable and start MariaDB service by executing systemctl command.

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service â /usr/lib/systemd/system/mariadb.service.

Configure MySQL server and set a strong password for root user.

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Install Nginx on CentOS 8:

Nextcloud is a PHP based web application, therefore, it requires a LAMP on LEMP server for deployment.

As per documentation use of Apache web server is recommended. However, Nextcloud also supports Nginx web server and we are using the same in this installation guide.

# dnf install nginx -y

Enable and start Nginx service by executing the systemctl command.

# systemctl enable --now nginx.service
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service â /usr/lib/systemd/system/nginx.service.

Allow Nginx service to be accessible across the network by allowing the relevant service ports in Linux firewall.

# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success

To verify that Nginx web server is accessible, open the URL http://nextcloud-01.centlinux.com in a web browser.

Nginx Default Homepage

Install PHP on CentOS 8:

Finally, you have to install PHP on your Linux server and integrate it with Nginx web server to form the LEMP stack.

We have list down all the required PHP extensions and we are installing all of them with a single dnf command.

# yum install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring php-common php-json php-curl php-zip php-bz2 php-intl -y

Configure PHP settings for integration with Nginx web server.

# vi /etc/php-fpm.d/www.conf

Locate following parameters.

user = apache
group = apache

and replace with following parameters.

user = nginx
group = nginx

Set following SELinux boolean to allow Nginx web server to execute external programs.

# setsebool -P httpd_execmem 1

Enable and start php-fpm.service by using systemctl command.

# systemctl enable --now php-fpm.service
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service â /usr/lib/systemd/system/php-fpm.service.

To Apply PHP configurations to your Nginx web server, you need to restart it.

# systemctl restart nginx.service

Create a sample PHP page with famous phpinfo() function, to verify the PHP support and check the installed modules.

# vi /usr/share/nginx/html/info.php

Add following PHP code therein.

<?php phpinfo(); ?>

Open URL https://nextcloud-01.centlinux.com/info.php in a web browser.

PHPinfo Page

Your LEMP server has been configured successfully.

Install Nextcloud on CentOS 8:

Nextcloud is free and open source, therefore you can easily download Nextcloud from their official website.

Download Nextcloud

Currently, Nextcloud 19 is available for download at their website.

Copy link location of Download Nextcloud button. You will use this URL to download the Nextcloud software from the Linux CLI.

Change directory to /tmp and use the copied URL with wget to download Nextcloud 19 installation archive.

# cd /tmp
# wget https://Nextclouddownload.nextcloud.com/server/releases/nextcloud-19.0.0.zip
--2020-07-12 22:02:38--  https://download.nextcloud.com/server/releases/nextcloud-19.0.0.zip
Resolving download.nextcloud.com (download.nextcloud.com)... 95.217.64.181, 2a01:4f9:2a:3119::181
Connecting to download.nextcloud.com (download.nextcloud.com)|95.217.64.181|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 111544326 (106M) [application/zip]
Saving to: ânextcloud-19.0.0.zipâ

nextcloud-19.0.0.zi 100%[===================>] 106.38M   126KB/s    in 18m 49s

2020-07-12 22:21:27 (96.5 KB/s) - ânextcloud-19.0.0.zipâ saved [111544326/111544326]

The downloaded Nextcloud software is in zip format, therefore, you require unzip utility to extract the contents of downloaded file.

If unzip is not already installed on your Linux server, then you can easily install it by executing dnf command.

# dnf install unzip -y

Extract the contents of downloaded file by using unzip command.

# unzip nextcloud-19.0.0.zip -d /usr/share/nginx/

We have used -d switch to extract the zip file directly into default document root directory of our Nginx web server.

Configure SELinux and File Permissions:

Adjust the file permission on Nextcloud server software.

# chown -R nginx:nginx /usr/share/nginx/nextcloud

You are also required to adjust owner-group of following PHP directories.

# chgrp -R nginx /var/lib/php/{opcache,session,wsdlcache}

Since, you are installing Nextcloud with SELinux in enforcing mode. Therefore, you need to add a custom “File Context” of the Nextcloud software directory in SELinux policies.

For this purpose, you can use semanage command. If semanage command is not available in your CentOS / RHEL 8 machine, then you have to install policycoreutils-python-utils package by using Linux package manager.

# semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/nextcloud(/.*)?'

Apply the newly added file context on the Nexcloud directory by using restorecon command.

# restorecon -R /usr/share/nginx/nextcloud

Create MariaDB Database:

Connect to MariaDB database server as root user.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 16
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

Create a MySQL database for Nextcloud server as follows.

MariaDB [(none)]> CREATE DATABASE nextcloud DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Query OK, 1 row affected (0.143 sec)

Create a user to own nextcloud database.

MariaDB [(none)]> CREATE USER ncuser@localhost IDENTIFIED BY 'Centlinux@123';
Query OK, 0 rows affected (0.209 sec)

Grant all privileges on nextcloud database to ncuser.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO ncuser@localhost;
Query OK, 0 rows affected (0.032 sec)

Reload privileges tables.

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.069 sec)

Exit from MariaDB shell.

MariaDB [(none)]> EXIT;
Bye

Configure Nginx for Nextcloud Server:

Edit /etc/nginx/nginx.conf configuration file.

# vi /etc/nginx/nginx.conf

Search and set following directive in this file.

server_name  nextcloud-01.centlinux.com;
root         /usr/share/nginx/nextcloud/;

Restart Nginx service to apply changes.

# systemctl restart nginx.service

Create a data directory for Nextcloud server. This directory is very important because it will hold all the files uploaded by using web interface.

# mkdir /usr/share/nginx/nextcloud/data

Set nginx user as owner of this directory.

# chown -R nginx:nginx /usr/share/nginx/nextcloud/data

Create a SELinux File Context for this directory. So, the nginx user can write on this directory.

# semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/nextcloud/data(/.*)?'

Apply the newly added file context on data directory.

# restorecon -R /usr/share/nginx/nextcloud/data/

Access Nextcloud web application by opening URL http://nextcloud-01.centlinux.com in a web browser.

Nextcloud Web Setup

You will be asked to

  • create an Admin user for Nextcloud
  • location of data directory
  • credentials to access Nextcloud database

You can enter the required information.

Nextcloud Hub

Click on “Finish Setup” and you will be routed to “Nextcloud Hub”.

By default, we have been logged in as Admin user. You can now use Nextcloud web interface to upload your files.

Conclusion – Install Nextcloud on CentOS 8:

In the above installation guide, you have successfully install Nextcloud on CentOS 8. If you faced difficulty in understanding the above tutorial, we strongly recommend you to read Linux Administration: A Beginner’s Guide, Eighth Edition (PAID LINK) by McGraw-Hill Education.

Scroll to Top