How to Install Nextcloud on CentOS 7/6 & / RHEL 7/6

NextCloud is an open source web suite that provides cloud storage over the network, fork of ownCloud. It is like a Dropbox that permits you to store and share your documents and pictures in a centralized location.

In this post, we will see how to Install Nextcloud on CentOS 7/6 & / RHEL 7/6.


  • Access your files anytime, anywhere.
  • Share your files with the other users. Create and send password protected public links.
  • Two-factor authentication with TOTP and QR code.
  • Monitor the activity on your NextCloud server.
  • NextCloud can access files stored in external cloud storage service providers such as Amazon, Google, and Dropbox.

More here.

System Requirements

Linux: Redhat Enterprise Linux 7 / CentOS 7 & RHEL 6 / CentOS 6, Ubuntu 16.04, Debian 9, SUSE Enterprise Server 11 SP3 & 12.

Apache 2 with mod_php

Database: MySQL / MariaDB, PostgreSQL, Oracle 11g.

PHP 5.6, 7.0 or 7.1

The commercial version of NextCloud is also available.


Enable Redhat software collection repository on RHEL 7 and RHEL 6.

### RHEL 7 ###

subscription-manager repos --enable rhel-server-rhscl-7-eus-rpms

### RHEL 6 ###

subscription-manager repos --enable rhel-server-rhscl-6-eus-rpms

ownCloud works only with PHP v5.6 and above. So, we need to configure Webtatic repository on CentOS / RHEL to get PHP 5.6, 7.0 or 7.1 packages. Also, we need to enable EPEL repository to get dependent packages.

### CentOS 7 / RHEL 7 ###

rpm -ivh
rpm -ivh

### CentOS 6 / RHEL 6 ###

rpm -ivh
rpm -ivh

Install the Apache server and other utilities.

yum install -y httpd wget bzip2

Install the PHP and its extensions using the yum command. Choose any one of the PHP versions.

### PHP 5.6 ###

yum install -y php56w php56w-common php56w-gd php56w-intl php56w-mbstring php56w-mcrypt php56w-mysqlnd php56w-process php56w-xml php56w-cli php56w-pdo 

### PHP 7.0 ###

yum install -y php70w php70w-common php70w-gd php70w-intl php70w-mbstring php70w-mcrypt php70w-mysqlnd php70w-process php70w-xml php70w-cli php70w-pdo 

### PHP 7.1 ###

yum install -y php71w php71w-common php71w-gd php71w-intl php71w-mbstring php71w-mcrypt php71w-mysqlnd php71w-process php71w-xml php71w-cli php71w-pdo

As mentioned earlier, it is based on PHP and database combination. The database can be any of from SQLite, MySQL/MariaDB, Oracle or PostgreSQL database.

For this demo, we will use MariaDB/MySQL as a database for ownCloud, and we will talk about the reason behind it later.

### CentOS 7 / RHEL 7 ###

yum -y install mariadb-server mariadb

### CentOS 6 / RHEL 6 ###

yum -y install mysql-server mysql

Download and Setup

NextCloud provides installable archives for server admins to download and manually set it up on top of LAMP stack. Download the latest version of Nextcloud using the terminal.

cd /tmp/ 

Extract the Nextcloud archive using the tar command.

tar -jxvf latest.tar.bz2

Move the extracted files to Apache’s document root and then create a data directory to hold the user data.

mv nextcloud /var/www/html/ 
mkdir /var/www/html/nextcloud/data

Set the ownership of the files inside the NextCloud directory so that apache user can write the data into it.

chown -R apache:apache /var/www/html/nextcloud/

Start the Apache and MariaDB/MySQL service using the following command.

### CentOS 7 / RHEL 7 ###

systemctl start httpd
systemctl start mariadb

### CentOS 6 / RHEL 6 ###

service httpd start
service mysqld start

Enable both Apache and MySQL/MariaDB service to start automatically at system start-up.

### CentOS 7 / RHEL 7 ###

systemctl enable httpd
systemctl enable mariadb

### CentOS 6 / RHEL 6 ###

chkconfig httpd on
chkconfig mysqld on

Create Database

If you are setting up a MariaDB for the first time, then

READ: Secure MariaDB with mysql_secure_installation

Ensure MariaDB service is running before attempting to create the database. Now, login to MariaDB server.

mysql -u root -p

Create a database called “nextclouddb“.

create database nextclouddb;

Allow “nextclouduser” to access the “nextclouddb” database on localhost with a predefined password.

grant all on nextclouddb.* to 'nextclouduser'@'localhost' identified by 'password';

Exit from the MariaDB prompt.



Set SELinux context to allow NextCloud to write the data inside its important directories.

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/data'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/config(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/apps(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/3rdparty(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/.htaccess'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/.user.ini'

restorecon -Rv '/var/www/html/nextcloud/'

If you get an error for semanage command not found, then

READ: semanage command not found on CentOS 7/6 & RHEL 7/6 – Quick Fix


Configure the firewall to allow access to the Nextcloud storage from external machines.


firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload


iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
service iptables save

Configure NextCloud

Open up your web browser, point a URL to


The browser will take you automatically to NextCloud setup page where you have to begin the setup of NextCloud.

Enter admin details (username and password), data folder location where all of your documents get saved, and database information.

You can choose either SQLite or MySQL/MariaDB. If you want to SQLite database, then you do not have to enter database details (not recommended for production use). Whereas MariaDB requires database user, password and database name.

For this tutorial, we will use MariaDB as a backend database.

Install Nextcloud on CentOS 7 - Nextcloud Setup Page
Install Nextcloud on CentOS 7 – Nextcloud Setup Page

Alternately you can download NextCloud client apps to manage files on the go.

Install Nextcloud on CentOS 7 - Nextcloud Apps
Install Nextcloud on CentOS 7 – Nextcloud Apps

The home page of NextCloud will look like below, and you can start uploading the contents using “+ sign” button.

Install Nextcloud on CentOS 7 - Upload Files
Install Nextcloud on CentOS 7 – Upload Files


If you have changed an IP address of Nextcloud server or the domain name you use to access the Nextcloud, you may get the below error.

Access through untrusted domain
Please contact your administrator. If you are an administrator, edit the "trusted_domains" setting in config/config.php like the example in config.sample.php.

Depending on your configuration, this button could also work to trust the domain:
Install Nextcloud on CentOS 7 - Access through untrusted domain
Install Nextcloud on CentOS 7 – Access through untrusted domain

To resolve the issue, either click the button shown on the above page or modify the config/config.php file.

vi /var/www/html/nextcloud/config/config.php

Add the trusted domains shown like below.

'trusted_domains' =>
  array (
    0 => '',
    1 => '',
    2 => 'your.fq.dn',
    3 => 'your.ip.add.ress',

That’s All.

Further Reading

You might also like

Comments are closed.