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 [ https://youtu.be/I2dS_pCPhKw ]

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

Install Epel- Repo

[root@docserver ~]# yum -y install 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/multi-user.target.wants/httpd.service → /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/ 
ServerName docserver.itpings.com 
<Directory>
Require all granted 
AllowOverride All
Options FollowSymLinks MultiViews
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
</VirtualHost>

:wq 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 https://download.nextcloud.com/server/releases/nextcloud-20.0.1.zip

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
/var/www/html/nextcloud
Here Create data directory
[root@docserver nextcloud]# mkdir data

Uncompress nextcloud-20.0.1.zip

[root@docserver opt]# unzip nextcloud-20.0.1.zip
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 https://rpms.remirepo.net/enterprise/remi-release-8.rpm

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/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
[root@docserver ~]# systemctl start redis

Installing PostgreSQl

**Note: [ All details of how to install Available on postgresql.org/download/linux/redhat page ]

Downloading postgresql rpm from external repo

[root@docserver ~]# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

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:
postgresql
Transaction Summary
Is this ok [y/N]: y
Complete!

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/multi-user.target.wants/postgresql-13.service → /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.
postgres=#

Creating Database user and Database for NextCloud

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

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 127.0.0.1/32 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://<youripaddress.com> of your machine and give details and complete the setup.

You will see Screen like this to login

Congratulations !

Thank you

Salman A. Francis
https://www.youtube.com/linuxking
https://www.tekco.net

Leave a Reply

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

Impact Financial

Good draw knew bred ham busy his hour. Ask agreed answer rather joy nature admire wisdom.

Latest Posts

  • All Posts
  • Amazon
  • Amazon EFS
  • apache
  • AWS
  • aws backup
  • aws cli
  • aws cli version 2
  • aws sync
  • Banking
  • bash scripting
  • Budgeting
  • cloud
  • cyber attack
  • cyber scam
  • database
  • efs
  • Email
  • Email Client
  • Email Server
  • Insurance
  • Investing
  • Learning
  • lets encrypt
  • Linux
  • php
  • pip
  • postgresql
  • python
  • S3
  • s3 buckets
  • scam prevention
  • scams
  • security
  • ssl
  • Tax Strategies
  • Troubleshooting
  • website
  • wordpress
  • wordpress setup
    •   Back
    • Linux tips
    •   Back
    • nextcloud
    •   Back
    • Rainloop

Categories

Tags