Setting up NextCloud on Centos 8 with Apache, Redis, PostgreSql, SSL & PhP 7.4

In this How we are going to setup our very own working NextCloud. So without wasting our time , lets start.

We need a working CentOs 8 Linux distro. If you don’t know how to install it, Follow my youtube video [ ]

Once we have our working CentOs 8, perform the following task:

Install Epel- Repo

[root@docserver ~]# yum -y intall epel-release

Update the Server

[root@docserver ~]# yum -y update

Install Apache & some important tools & utilities.

[root@docserver ~]# yum -y install httpd yum-utils unzip policycoreutils-python-utils mlocate bzip2 tar vim wget
[root@docserver ~]# httpd -v
Server version: Apache/2.4.37 (centos)
Server built: Sep 15 2020 15:41:16

Start and enable Apache

[root@docserver ~]# systemctl enable httpd
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/httpd.service.
[root@docserver ~]# systemctl start httpd

Create a Virtual host

[root@docserver ~]# vim /etc/httpd/conf.d/nextcloud.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/nextcloud/
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
<IfModule mod_dav.c> 
Dav off 

save and quit

Install mod_ssl

[root@docserver ~]# yum -y install mod_ssl

Adding firewall rules for port 80 and 443

[root@docserver ~]# firewall-cmd --add-port=80/tcp --permanent
[root@docserver ~]# firewall-cmd --add-port=443/tcp --permanent
[root@docserver ~]# firewall-cmd --reload

Add User for NextCloud Server

[root@docserver ~]# useradd nextcloud
[root@docserver ~]# passwd nextcloud
[root@docserver ~]# usermod -a nextcloud -G wheel
[root@docserver ~]# id nextcloud
uid=1001(nextcloud) gid=1001(nextcloud) groups=1001(nextcloud),10(wheel)

Download NextCloud in zip or tar format

[root@docserver opt]# wget

Create Directory nextcloud inside /var/www/html

[root@docserver opt]# mkdir /var/www/html/nextcloud
[root@docserver opt]# cd /var/www/html/nextcloud
[root@docserver nextcloud]# pwd
Here Create data directory
[root@docserver nextcloud]# mkdir data


[root@docserver opt]# unzip
copy the content of nexcloud folder to /var/www/html/nextcloud

Now Make sure you set the permission properly

[root@docserver var]# chown apache:apache -R www/
[root@docserver var]# chmod 775 -R www/
[root@docserver var]# systmectl restart httpd

Installing PHP 7.4

Downoading rpm from Remi Repo

[root@docserver ~]# yum -y install

Enable Remi Repo

[root@docserver ~]# yum module reset php
[root@docserver ~]# yum -y module install php:remi-7.4

Now install required php modules

[root@docserver ~]# yum -y install php-mbstring php php-gd php-intl php-pecl-apcu php-opcache php-json php-pecl-zip php-pear php-pecl-imagick php-fpm php-pecl-redis5 php-pgsql php-common php-pdo php-xml php-lz4 php-pecl-crypto php-pecl-rar php-pecl-pq php-pecl-lzf php-cli php-pecl-apcu-bc

Installing REDIS [ Opensource Cache ]

[root@docserver ~]# yum -y install redis
[root@docserver ~]# systemctl enable redis
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/redis.service.
[root@docserver ~]# systemctl start redis

Installing PostgreSQl

**Note: [ All details of how to install Available on page ]

Downloading postgresql rpm from external repo

[root@docserver ~]# yum install

Now Disable PostgreSQL from CentOS repository

[root@docserver ~]# yum module disable postgresql
Failed to set locale, defaulting to C.UTF-8
PostgreSQL common RPMs for RHEL/CentOS 8 - x86_ 840 kB/s | 476 kB 00:00
PostgreSQL 13 for RHEL/CentOS 8 - x86_64 446 kB/s | 184 kB 00:00
PostgreSQL 12 for RHEL/CentOS 8 - x86_64 895 kB/s | 408 kB 00:00
PostgreSQL 11 for RHEL/CentOS 8 - x86_64 1.2 MB/s | 598 kB 00:00
PostgreSQL 10 for RHEL/CentOS 8 - x86_64 865 kB/s | 403 kB 00:00
PostgreSQL 9.6 for RHEL/CentOS 8 - x86_64 869 kB/s | 392 kB 00:00
PostgreSQL 9.5 for RHEL/CentOS 8 - x86_64 707 kB/s | 346 kB 00:00
Dependencies resolved.
Package Architecture Version Repository Size
Disabling modules:
Transaction Summary
Is this ok [y/N]: y

Now Installing Postgresql from External Repo

[root@docserver ~]# yum install -y postgresql13-server

Initialize the database and enabling it

[root@docserver ~]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database … OK
[root@docserver ~]# systemctl enable postgresql-13
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/postgresql-13.service.
[root@docserver ~]# systemctl start postgresql-13

Setup password and switching user

[root@docserver ~]# passwd postgres
Now switch to postgres user
[root@docserver ~]# su -l postgres

Entering Database

[postgres@docserver ~]$ psql
psql (13.1)
Type "help" for help.

Creating Database user and Database for NextCloud

postgres=# create user nextclouduser with password 'abc123';
Create a database
postgres=# create database nextclouddb;
Give NextCloud user rights to access the database.
postgres=# grant all privileges on database nextclouddb to nextclouduser;
Now exit
postgres=# \q
[postgres@docserver ~]$ exit

Make sure the following is enabled in PostgreSql Config

Now we need to enable connection

[root@docserver ~]# vim /var/lib/pgsql/13/data/pg_hba.conf
IPv4 local connections:

host all all scram-sha-256 [ we can check with md5 as well ]

[root@docserver ~]# systemctl restart postgresql-13

Now we would install Lets Encrypt for SSL

[root@docserver nextcloud]# yum install snapd
[root@docserver nextcloud]# snap install core
[root@docserver nextcloud]# systemctl start snapd
[root@docserver nextcloud]# systemctl enable snapd
[root@docserver nextcloud]# ln -s /var/lib/snapd/snap /snap
[root@docserver nextcloud]# snap install --classic certbot
[root@docserver nextcloud]# certbot --apache
Follow the instructions and thats it !

Open your Browser and type the ip address https://<> of your machine and give details and complete the setup.

You will see Screen like this to login

Congratulations !

Thank you

Salman A. Francis

Leave a Comment

Your email address will not be published. Required fields are marked *