Nextcloud is a free (Open Source) Dropbox-like software, a fork of the ownCloud project. Nextcloud is written in php and javascript, it supports many database systems such as, mysql/MariaDB, PostgreSQL, Oracle Database and SQLite. In order to keep your files synchronized between Desktop and your own server, Nextcloud provides applications for windows, linux and Mac desktops and a mobile app for android and iOS. Nextcloud is not just a dropbox clone, it provides additional features like Calendar, Contacts, Schedule tasks, and streaming media with Ampache.
In this tutorial, I will show you how to install and configure the latest Nextcloud 10 release on a CentOS 7 server. I will run Nextcloud with a Nginx web server and PHP7-FPM and use MariaDB as the database system.
Prerequisite CentOS 7 64bit Root privileges on the server Step 1 - Install Nginx and PHP7-FPM on CentOS 7Before we start with the Nginx and php7-fpm installation, we have to add the EPEL package repository. Install it with this yum command.
yum -y install epel-release
Now install Nginx from the EPEL repository.
yum -y install nginx
Then we have to add another repository for php7-fpm. There are several repositories available on the net that provide PHP 7 packages, I will use webtatichere.
Add the PHP7-FPM webtatic repository:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Next, install PHP7-FPM and some additional packages for the Nextcloud installation.
yum -y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel
Finally, check the PHP version from server terminal to verify that PHP installed correctly.
php -v

Step 2 - Configure PHP7-FPM
In this step, we will configure php-fpm to run with Nginx. Php7-fpm will run under user nginx and listen on port 9000.
Edit the default php7-fpm configuration file with vim.
vim /etc/php-fpm.d/www.conf
In line 8 and 10, change user and group to ' nginx '.
user = nginx
group = nginx
In line 22, make sure php-fpm is running under server port.
listen = 127.0.0.1:9000
Uncomment line 366-370 to activate the php-fpm system environment variables.
env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmpSave the file and exit the vim editor.
Next, create a new directory for the session path in the '/var/lib/' directory, and change the owner to the 'nginx' user.
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
Now start php-fpm and Nginx, then enable the services to start at boot time.
sudo systemctl start php-fpm
sudo systemctl start nginx
sudo systemctl enable php-fpm
sudo systemctl enable nginx

PHP7-FPM configuration is done.
Step 3 - Install and Configure MariaDBIwill use MariaDB for the Nextcloud database. Install themariadb-server package from the CentOS repository with yum.
yum -y install mariadb mariadb-server
Start the MariaDB service and add it to run at boot time.
systemctl start mariadb
systemctl enable mariadb
Now configure the MariaDB root password.
mysql_secure_installation
Type in your root password when requested.
Set root password? [Y/n] YNew password:
Re-enter new password:
Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] YThe MariaDB root password has been set, now we can login to the mysql shell to create a new database and a new user for Nextcloud. I will create a new database named ' nextcloud_db ' and a user ' nextclouduser ' with password ' nextclouduser@ '. Choose a secure password for your installation!
mysql -u root -p
Type Password
Type in the mysql query below to create a new database and a new user.
create database nextcloud_db;
create user[emailprotected]identified by 'nextclouduser@';
grant all privileges on nextcloud_db.* to[emailprotected] identified by 'nextclouduser@';flush privileges;

The nextcloud_db database with user 'nextclouduser' has been created.
Step 4 - Generate a Self-signed SSL Certificate for NextcloudIn this tutorial, I will run nextcloud with a https connection for the client. You can use free SSL such as let's encrypt or create self signed SSL certificate.I will create my own self-signed SSL certificate file with the OpenSSL command.
Create a new directory for the SSL file.
mkdir -p /etc/nginx/cert/
And generate a new SSL certificate file with the theopenssl command below.
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
Finally, change the permission of all certificate files to 600 with chmod.
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*

Step 5 - Download and Install Nextcloud
We will download Nextcloud with wget directly to the server, so we have to install wget first. Additionally, we need the unzip program. Install both applications with yum.
yum -y install wget unzip
Go to the /tmp directory and download latest stable Nextcloud 10 version from the Nextcloud web site with wget.
cd /tmp
wget https://download.nextcloud.com/server/releases/nextcloud-10.0.2.zip
Extract the nextcloud zip file and move it's content to the '/usr/share/nginx/html/' directory.
unzip nextcloud-10.0.2.zip
mv nextcloud/ /usr/share/nginx/html/
Next, go to the Nginx web root directory and create a new 'data' directory for Nextcloud.
cd /usr/share/nginx/html/
mkdir -p nextcloud/data/
Change the owner of the 'nextcloud' directory to the 'nginx' user and group.
chown nginx:nginx -R nextcloud/
Step 6 - Configure Nextcloud Virtual Host in NginxIn step 5 we've downloaded the Nextcloud source code and configured it to run under the Nginx web server. But we still need to configure a virtual host for Nextcloud. Create a new virtual host configuration file 'nextcloud.conf' in the Nginx 'conf.d' directory.
cd /etc/nginx/conf.d/
vim nextcloud.conf
Paste the Nextcloud virtual host configuration below.
upstream php-handler { server 127.0.0.1:9000; #server unix:/var/run/php5-fpm.sock; } server { listen 80; server_name cloud.nextcloud.co; # enforce https return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name cloud.nextcloud.co; ssl_certificate /etc/nginx/cert/nextcloud.crt; ssl_certificate_key /etc/nginx/cert/nextcloud.key; # Add headers to serve security related headers # Before enabling Strict-Transport-Security headers please read into this # topic first. add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; add_header X-Content-Type-Options nosniff; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=bl