Install Nextcloud Server with Nginx on CentOS 8 - CentLinux


Saturday, 18 July 2020

Install Nextcloud Server with Nginx on CentOS 8

Install Nextcloud Server with Nginx on CentOS 8

Nextcloud is a private cloud storage software. In this article, you will learn how to install Nextcloud server with Nginx on CentOS 8.


Table of Contents:


What is Nextcloud? :

Nextcloud is a free and open source software for creating and using web based file hosting services. Nextcloud 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 8.2
  • Hostname –
  • IP Address - /24


Update CentOS 8 Software Packages:

Connect with as root user by using a SSH client such as PuTTY.

Use dnf command to update software packages on our CentOS 8 server.

[root@nextcloud-01 ~]# dnf update -y Last metadata expiration check: 0:00:10 ago on Sat 11 Jul 2020 01:28:15 PM PKT. Dependencies resolved. ================================================================================ Package Arch Version Repo Size ================================================================================ Upgrading: bind-export-libs x86_64 32:9.11.13-5.el8_2 BaseOS 1.1 M gnutls x86_64 3.6.8-11.el8_2 BaseOS 915 k libnghttp2 x86_64 1.33.0-3.el8_2.1 BaseOS 77 k microcode_ctl x86_64 4:20191115-4.20200609.1.el8_2 BaseOS 2.7 M Transaction Summary ================================================================================ Upgrade 4 Packages Total download size: 4.8 M Downloading Packages: (1/4): libnghttp2-1.33.0-3.el8_2.1.x86_64.rpm 381 kB/s | 77 kB 00:00 (2/4): gnutls-3.6.8-11.el8_2.x86_64.rpm 407 kB/s | 915 kB 00:02 (3/4): bind-export-libs-9.11.13-5.el8_2.x86_64. 472 kB/s | 1.1 MB 00:02 (4/4): microcode_ctl-20191115-4.20200609.1.el8_ 712 kB/s | 2.7 MB 00:03 -------------------------------------------------------------------------------- Total 1.0 MB/s | 4.8 MB 00:04 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: microcode_ctl-4:20191115-4.20200609.1.el8_2.x86_64 1/1 Upgrading : microcode_ctl-4:20191115-4.20200609.1.el8_2.x86_64 1/8 Running scriptlet: microcode_ctl-4:20191115-4.20200609.1.el8_2.x86_64 1/8 Upgrading : libnghttp2-1.33.0-3.el8_2.1.x86_64 2/8 Upgrading : gnutls-3.6.8-11.el8_2.x86_64 3/8 Upgrading : bind-export-libs-32:9.11.13-5.el8_2.x86_64 4/8 Running scriptlet: bind-export-libs-32:9.11.13-5.el8_2.x86_64 4/8 Running scriptlet: microcode_ctl-4:20191115-4.20200602.2.el8_2.x86_64 5/8 Cleanup : microcode_ctl-4:20191115-4.20200602.2.el8_2.x86_64 5/8 Running scriptlet: microcode_ctl-4:20191115-4.20200602.2.el8_2.x86_64 5/8 Cleanup : libnghttp2-1.33.0-1.el8_0.1.x86_64 6/8 Cleanup : gnutls-3.6.8-10.el8_2.x86_64 7/8 Cleanup : bind-export-libs-32:9.11.13-3.el8.x86_64 8/8 Running scriptlet: bind-export-libs-32:9.11.13-3.el8.x86_64 8/8 Running scriptlet: microcode_ctl-4:20191115-4.20200609.1.el8_2.x86_64 8/8 Running scriptlet: bind-export-libs-32:9.11.13-3.el8.x86_64 8/8 Verifying : bind-export-libs-32:9.11.13-5.el8_2.x86_64 1/8 Verifying : bind-export-libs-32:9.11.13-3.el8.x86_64 2/8 Verifying : gnutls-3.6.8-11.el8_2.x86_64 3/8 Verifying : gnutls-3.6.8-10.el8_2.x86_64 4/8 Verifying : libnghttp2-1.33.0-3.el8_2.1.x86_64 5/8 Verifying : libnghttp2-1.33.0-1.el8_0.1.x86_64 6/8 Verifying : microcode_ctl-4:20191115-4.20200609.1.el8_2.x86_64 7/8 Verifying : microcode_ctl-4:20191115-4.20200602.2.el8_2.x86_64 8/8 Upgraded: bind-export-libs-32:9.11.13-5.el8_2.x86_64 gnutls-3.6.8-11.el8_2.x86_64 libnghttp2-1.33.0-3.el8_2.1.x86_64 microcode_ctl-4:20191115-4.20200609.1.el8_2.x86_64 Complete!


Installing MariaDB Database Server 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, we are installing MariaDB server on CentOS 8 operating system.

[root@nextcloud-01 ~]# dnf install -y mariadb-server ... Installed: mariadb-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-backup-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-common-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-connector-c-3.0.7-1.el8.x86_64 mariadb-connector-c-config-3.0.7-1.el8.noarch mariadb-errmsg-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-gssapi-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-server-utils-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 perl-Carp-1.42-396.el8.noarch perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64 perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64 perl-Data-Dumper-2.167-399.el8.x86_64 perl-Digest-1.17-395.el8.noarch perl-Digest-MD5-2.55-396.el8.x86_64 perl-Encode-4:2.97-3.el8.x86_64 perl-Errno-1.28-416.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-File-Temp-0.230.600-1.el8.noarch perl-Getopt-Long-1:2.50-4.el8.noarch perl-HTTP-Tiny-0.074-1.el8.noarch perl-IO-1.38-416.el8.x86_64 perl-IO-Socket-IP-0.39-5.el8.noarch perl-IO-Socket-SSL-2.066-4.el8.noarch perl-MIME-Base64-3.15-396.el8.x86_64 perl-Math-BigInt-1:1.9998.11-7.el8.noarch perl-Math-Complex-1.59-416.el8.noarch perl-Mozilla-CA-20160104-7.el8.noarch perl-Net-SSLeay-1.88-1.el8.x86_64 perl-PathTools-3.74-1.el8.x86_64 perl-Pod-Escapes-1:1.07-395.el8.noarch perl-Pod-Perldoc-3.28-396.el8.noarch perl-Pod-Simple-1:3.35-395.el8.noarch perl-Pod-Usage-4:1.69-395.el8.noarch perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-3.el8.x86_64 perl-Storable-1:3.11-3.el8.x86_64 perl-Term-ANSIColor-4.06-396.el8.noarch perl-Term-Cap-1.17-395.el8.noarch perl-Text-ParseWords-3.30-395.el8.noarch perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Time-Local-1:1.280-1.el8.noarch perl-URI-1.73-3.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-416.el8.x86_64 perl-libnet-3.11-3.el8.noarch perl-libs-4:5.26.3-416.el8.x86_64 perl-macros-4:5.26.3-416.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 psmisc-23.1-4.el8.x86_64 Complete!

Enable and start MariaDB service by using systemctl command.

[root@nextcloud-01 ~]# 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/ â /usr/lib/systemd/system/mariadb.service.

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

[root@nextcloud-01 ~]# 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!


Installing Nginx on CentOS 8:

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

As per Nextcloud 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.

[root@nextcloud-01 ~]# dnf install nginx -y ... Installed: dejavu-fonts-common-2.35-6.el8.noarch dejavu-sans-fonts-2.35-6.el8.noarch fontconfig-2.13.1-3.el8.x86_64 fontpackages-filesystem-1.44-22.el8.noarch gd-2.2.5-6.el8.x86_64 jbigkit-libs-2.1-14.el8.x86_64 libX11-1.6.8-3.el8.x86_64 libX11-common-1.6.8-3.el8.noarch libXau-1.0.8-13.el8.x86_64 libXpm-3.5.12-8.el8.x86_64 libjpeg-turbo-1.5.3-10.el8.x86_64 libtiff-4.0.9-17.el8.x86_64 libwebp-1.0.0-1.el8.x86_64 libxcb-1.13.1-1.el8.x86_64 nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 Complete!

Enable and start Nginx service by using the systemctl command.

[root@nextcloud-01 ~]# systemctl enable --now nginx.service Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/nginx.service.

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

[root@nextcloud-01 ~]# firewall-cmd --permanent --add-service=http success [root@nextcloud-01 ~]# firewall-cmd --reload success

To verify that Nginx web server is accessible, open the URL in a web browser.



Install PHP on CentOS 8:

Finally, we have to install PHP on our 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.

[root@nextcloud-01 ~]# 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 ... Installed: apr-1.6.3-9.el8.x86_64 apr-util-1.6.1-6.el8.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64 centos-logos-httpd-80.5-2.el8.noarch httpd-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64 httpd-filesystem-2.4.37-21.module_el8.2.0+382+15b0afa8.noarch httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64 libzip-1.5.1-2.module_el8.2.0+313+b04d0a66.x86_64 mailcap-2.1.48-3.el8.noarch mod_http2-1.11.3-3.module_el8.2.0+307+4d18d695.x86_64 php-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-cli-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-common-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-fpm-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-gd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-intl-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-json-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-mbstring-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-opcache-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-pdo-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-pecl-zip-1.15.3-1.module_el8.2.0+313+b04d0a66.x86_64 php-xml-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 Complete!

Configure PHP settings for integration with Nginx web server.

[root@nextcloud-01 ~]# 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.

[root@nextcloud-01 ~]# setsebool -P httpd_execmem 1

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

[root@nextcloud-01 ~]# systemctl enable --now php-fpm.service Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/php-fpm.service.

To Apply PHP configurations to our Nginx web server, we need to restart it.

[root@nextcloud-01 ~]# systemctl restart nginx.service

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

[root@nextcloud-01 ~]# vi /usr/share/nginx/html/info.php

Add following PHP code therein.

<?php phpinfo(); ?>

Open URL in a web browser.


Our LEMP server has been configured successfully.


Installing Nextcloud Server on CentOS 8:

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


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

Copy link location of Download Nextcloud button. We will use this URL to download the Nextcloud software from the Linux server command-line.

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

[root@nextcloud-01 ~]# cd /tmp [root@nextcloud-01 tmp]# wget --2020-07-12 22:02:38-- Resolving (, 2a01:4f9:2a:3119::181 Connecting to (||: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, we are required unzip utility extract the contents of Nextcloud downloaded file.

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

[root@nextcloud-01 tmp]# dnf install unzip -y ... Installed: unzip-6.0-43.el8.x86_64 Complete!

Extract the contents of Nextcloud downloaded file by using unzip command.

[root@nextcloud-01 tmp]# unzip -d /usr/share/nginx/ ... creating: /usr/share/nginx/nextcloud/resources/codesigning/ inflating: /usr/share/nginx/nextcloud/resources/codesigning/root.crt inflating: /usr/share/nginx/nextcloud/resources/codesigning/root.crl inflating: /usr/share/nginx/nextcloud/resources/codesigning/core.crt creating: /usr/share/nginx/nextcloud/ocm-provider/ inflating: /usr/share/nginx/nextcloud/ocm-provider/index.php

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 for Nextcloud:

Adjust the file permission on Nextcloud server software.

[root@nextcloud-01 ~]# chown -R nginx:nginx /usr/share/nginx/nextcloud

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

[root@nextcloud-01 ~]# chgrp -R nginx /var/lib/php/{opcache,session,wsdlcache}

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

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

[root@nextcloud-01 ~]# 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.

[root@nextcloud-01 ~]# restorecon -R /usr/share/nginx/nextcloud


Create MariaDB Database for Nextcloud server:

Connect to MariaDB database server as root user.

[root@nextcloud-01 ~]# 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 Server for Nextcloud:

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

[root@nextcloud-01 ~]# vi /etc/nginx/nginx.conf

Search and set following directive in this file.

server_name; root /usr/share/nginx/nextcloud/;

Restart Nginx service to apply changes.

[root@nextcloud-01 ~]# 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 Nextcloud web interface.

[root@nextcloud-01 ~]# mkdir /usr/share/nginx/nextcloud/data

Set nginx user as owner of this directory.

[root@nextcloud-01 ~]# 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.

[root@nextcloud-01 ~]# semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/nextcloud/data(/.*)?'

Apply the newly added file context on data directory.

[root@nextcloud-01 ~]# restorecon -R /usr/share/nginx/nextcloud/data/

Access Nextcloud web application by opening URL in a web browser.


You will be asked to

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

We have entered the required information as follows.


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

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



In the above installation guide, we have successfully installed Nextcloud server with Nginx 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 by McGraw-Hill Education.

No comments:

Post a Comment