There are various cloud services available for you to store your data which include Google Drive, Microsoft Onedrive, and DropBox. The only thing not awesome with these services is that they are commercial services and you trust them to keep your data safe. What if there is an alternative to these commercial services? That is where Nextcloud comes in.

Nextcloud is a free and open-source platform that enables you to create your cloud service and is accessible wherever you want. It lets you stay in full control and protect the privacy of your data. It supports a wide range of apps like spreadsheets, documents, and presentations while also keeping calendar appointments and contacts. All these services are available via a web interface.

Nextcloud gives you access to all your files from wherever you are across any platform, whether at work, home, or road. With Nextloud you are eligible for constant improvements from the open-source community development models. You can choose to keep data on your server or on a data center that you trust with guaranteed compliance with business and legal requirements. Nextcloud was formed to focus on File syncing and sharing services, but they have expanded their toolset to include;

  • Nextcloud Talk for screen sharing, online meetings, and web conferencing without data leaks.
  • Nextcloud Groupware offers webmail, calendaring, and contacts integrated with Nextcloud files.

This guide shows you how to install Nextcloud on CentOS 9|AlmaLinux 9|RHEL 9.

Set up System for Nextcloud

Before installing Nextcloud, we need to have a few modules that will help run Nextcloud.

Pre-requisites

Install the LAMP Stack on your system. If not, follow through with this guide on Installing LAMP Stack on CentOS 9|AlmaLinux 9|RHEL 9.

You will also need to enable the EPEL repository on your system.

Install required dependencies for the installation

sudo dnf install -y yum-utils unzip curl wget bash-completion policycoreutils-python-utils mlocate bzip2

Install PHP extra modules.

sudo dnf install -y php-gd php-mbstring php-intl php-pecl-apcu php-mysqlnd php-opcache php-json php-zip

Then update your system.

sudo dnf update -y

Create Apache Virtualhost for Nextcloud

Create a virtual host for Nextcloud in the apache directory.

sudo vi /etc/httpd/conf.d/nextcloud.conf

Add the following content while specifying your server name and the root directory where you will store nextcloud files.

<VirtualHost *:80>
  DocumentRoot /var/www/html/nextcloud/
  ServerName  nextcloud.technix.com

  <Directory /var/www/html/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    <IfModule mod_dav.c>
      Dav off
    </IfModule>

  </Directory>
</VirtualHost>

Restart apache service

sudo systemctl restart httpd

Create Database for Nextcloud

Start the MySQL command-line tool

sudo mysql -u root -p

Enter the following lines

CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'StrongPassword';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES on nextcloud.* to 'nextcloud'@'localhost';
FLUSH privileges;

Quit with the following command.

quit;

Install NextCloud on CentOS 9|AlmaLinux 9|RHEL 9

Download Nextcloud latest release of Nextcloud Server from the Download page. Go to the Download Server section and click on Download for Server under Archive file. You can alternatively use the wget command to download it as shown below.

wget https://download.nextcloud.com/server/releases/latest.zip

Unzip the file to the /var/www/html/ directory.

sudo unzip latest.zip -d /var/www/html

Create a data folder to help with the installation

sudo mkdir /var/www/html/nextcloud/data

Set permissions to Apache for the whole Nextcloud folder.

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

Restart the Apache server.

sudo systemctl restart httpd

Create the firewall rule to allow apache access.

sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

SELinux Configuration

If you have SELinux enabled on your Linux Distribution. You may need to run some commands to configure Nextcloud. More configuration settings can be found on the SELinux Configuration page. For this guide, Run the following commands.

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

sudo restorecon -R '/var/www/html/nextcloud/'
sudo setsebool -P httpd_can_network_connect on

Once you are done with the configuration head over to your http://your-domain.com/ and continue with the next installation steps on Installation Wizard. The first thing to do is to create an account for administrative tasks.

As we want to use MySQL/MariaDB database, click on Storage & database then select the database type, and enter the details that we created above for the Database. Then click on Install. You can also choose to continue with the SQLite database for inial development instances.

The next page lists the recommended apps to install.

Your setup is finished and you will see the dashboard page as shown below.

You can click on Profile to view other details that you can add like profile picture, Email, Role, organization, About, Languages, Locale, Headline, etc.

The Files section contains a list of your files.

The mail section allows you to connect your mail account or do a manual connection.

The Talk section allows you to start conversations with colleagues and friends.

The Photos Sections allow you to view your photos.

The contacts section allows you to add contacts

The Calendar Tab allows you to schedule events and configure appointments.

Next

Create a user on Nextcloud

To create a user, Go to Users then click on New user.

Then enter the details of the New User then click on

You will be required to enter the Admin password to authorize the user creation. The user will then be added to the list of other users as shown below.

Other actions can be done to the user as shown below.

Install Addons on Nextcloud

Nextcloud offers Apps that can be installed on the server to customize it further and improve its functionalities. They can be found on the Apps webpage on Nextcloud Site.

However, you have to connect the server to the website to access the available apps. For this, edit the configuration file and add the following entries.

$ sudo vi /var/www/html/nextcloud/confi/config.php
'appstoreenabled' => true,
'appstoreurl' => 'https://apps.nextcloud.com/api/v1',
'appsallowlist' => [],
'apps_paths' => [
        [
                'path'=> '/var/www/html/nextcloud/apps',
                'url' => '/apps',
                'writable' => true,
        ],
],
'appcodechecker' => true,

Save and exit the file then refresh your server on the web.

Go to Apps then on available apps you will view them as shown. Click on the app you want to install, in my case, Breeze Dark theme, Then click Download and Enable.

Next, Go to Settings > Theming.

Then scroll to Breeze Dark. Click on the Checkbox to enable the theme by default.

Then refresh the page to see the changes.

Secure Nextcloud with SSL

Prerequisites

  • Self-signed Certificate stored in /etc/pki/tls/certs directory
  • Let’s Encrypt Certificate stored in /etc/letsencrypt/live/nextcloud.technix.com/ directory

Configure the Firewall to enable HTTPS access.

sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --reload

Install the mod_ssl package.

sudo dnf install mod_ssl

Self-signed Certificate

Open the SSL configuration file and set paths to the corresponding keys.

$ sudo vi /etc/httpd/conf.d/ssl.conf
SSLCertificateKeyFile "/etc/pki/tls/certs/server.key"
SSLCertificateFile "/etc/pki/tls/certs/server.crt"

Configure only the root to have access to the keys.

sudo chown root:root /etc/pki/tls/certs/server.key
sudo chmod 600 /etc/pki/tls/certs/server.key

Restart Apache server

sudo systemctl restart httpd

Let’s Encrypt certificate

Open the SSL configuration file and set the key’s path.

$ sudo vi /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/letsencrypt/live/nextcloud.technix.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/nextcloud.technix.com/privkey.pem

Configure only the root to have access to the keys.

sudo chown root:root /etc/letsencrypt/live/nextcloud.technix.com/fullchain.pem
sudo chmod 600 /etc/letsencrypt/live/nextcloud.technix.com/fullchain.pem

Restart the Apache Web server

sudo systemctl restart httpd

Use your browser to access https://your-domain.com/nextcloud.

Configure Nginx as HTTPD Proxy.

Install Nginx with the following command.

sudo dnf install nginx

Edit the main configuration file to add the root folder and the following details to the server block.

$ sudo vi /etc/nginx/nginx.conf
listen                3200;
listen                [::]:3200;
server_name      nextcloud.example.com;
root                   /var/www/html/nextcloud;

location / {
    proxy_pass http://nextcloud.technix.com;
}

Save and exit the file.

Edit the Nextcloud configuration file to add the server name to the trusted domains.

$ sudo vi /var/www/html/nextcloud/config/config.php
'trusted_domains' => 
  array (
    0 => 'nextcloud.technix.com',
    1 => 'nextcloud.example.com',
  ),

Configure SELinux to allow Nginx to forward traffic.

sudo setsebool -P httpd_can_network_connect 1
sudo  semanage port -a -t http_port_t -p tcp 3200
sudo semanage port -m -t http_port_t -p tcp 3200

Start and enable the service to autostart at boot.

sudo systemctl enable --now nginx

Check the status of the service.

$ sudo systemctl status nginx
 nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor pre>
    Drop-In: /usr/lib/systemd/system/nginx.service.d
             └─php-fpm.conf
     Active: active (running) since Wed 2022-06-29 14:18:44 EAT; 7s ago
    Process: 10259 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, sta>
    Process: 10260 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCE>
    Process: 10261 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
   Main PID: 10262 (nginx)
      Tasks: 3 (limit: 48771)
     Memory: 3.5M
        CPU: 30ms
     CGroup: /system.slice/nginx.service
             ├─10262 "nginx: master process /usr/sbin/nginx"
             ├─10263 "nginx: worker process"
             └─10264 "nginx: worker process"

Use a browser to connect to http://nextcloud.example.com.

Conclusion

We have looked at an overview of available cloud services and Nextcloud. We have also installed Nextcloud on CentOS 9|AlmaLinux 9|RHEL 9 systems. Nextcloud offers the option of having control of your data, whether in an office or a home set up in a free and secure way.

More guides to check out:

LEAVE A REPLY

Please enter your comment!
Please enter your name here