Setup Open Source NextCloud server on AlmaLinux 8

Step-by-step tutorial to install NextCloud on AlmaLinux 8 for personal cloud storage to store media files and documents using the internet from anywhere; using a smartphone or desktop app.

What is Nextcloud?

Nextcloud is free and open-source server-client architecture software whose source code is available on GitHub. It is a fork of another popular personal cloud solution “OwnCloud”.

Any user or enterprise can use it to build their cloud similar to Google Drive, iCloud, Dropbox, and Onedrive. Where to sync and access data (upload and download) automatically with a local directory users can use the Next Cloud client application for smartphones and Desktops.

This means that a consistent database can be accessed from several computers, but also via a web interface. Although Nextcloud is based on PHP, only Linux is supported as a server environment. It is also not possible to use Apache or NGINX with PHP on Windows.

Steps to install NextCloud on AlmaLinux 8

The steps given here will be applicable to other RedHat-based Linux distros such as CentOS, Rocky Linux, and Oracle Linux…

1. Requirements

AlmaLinux 8 or Oracle Linux, Redhat, RockyLinux…
Apache, PHP 7.3, 7.4, 8.0
MySQL 8.0+ or MariaDB 10.2/10.3/10.4/10.5
Non-root sudo user
512MB of RAM

2. Run system update

If you have just installed a fresh AlmaLinux server or haven’t updated it for a while then first run the system update command:

sudo dnf update & sudo dnf upgrade

Also, install:

sudo dnf install wget nano unzip

3. Disable SELinux in AlmaLinux 8

Once the update is completed, also put SELinux in permissive mode, which means disabling it temporarily until the next reboot. This will make sure there will be no unwanted restrictions in installing NextCloud.

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

To check the status:

sestatus
Disable SELinux in Rocky Linux

4. Install Apache (httpd)

As one of the requirements of NextCloud is the web server, so for that install Apache, along with that being a PHP based web application also configure the same.

sudo dnf install httpd wget

Start and enable Apache services

sudo systemctl enable --now httpd

To check the status:

sudo systemctl status httpd

5. PHP 8.0 + extensions for NextCloud in AlmaLinux 8

According to NextCloud, PHP 8.0 is recommended to use. Hence, we go for that because the version via the default repository of AlmaLinux is 7.2. Therefore,  we have to add the Remi repo manually to get the latest version.

sudo dnf install epel-release
sudo dnf -y install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf update
sudo dnf module reset php
sudo dnf module enable php:remi-8.0

Install:

sudo dnf -y install php php-cli php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pdo php-pecl-apcu php-pecl-apcu-devel php-ldap

Increase PHP Memory limit:

sudo sed -i "s/memory_limit = .*/memory_limit = 512M /" /etc/php.ini

5. Setup MariaDB and create a database

We also need some medium to store the data generated by NextCloud, here we are using MariaDB. However, you can use MySQL, SQLite, Oracle Database, and PostgreSQL as well if you want.

sudo dnf install mariadb-server mariadb

Start and enable the service:

sudo systemctl enable --now mysqld

Secure Database:

sudo mysql_secure_installation

Follow the text-based wizard.

Create a New Database for NextCloud:

Login:

mysql -u root -p

Create database User:

CREATE USER 'youruser'@'localhost' IDENTIFIED BY "yourpassword";

Create DB:

CREATE DATABASE yourdb;

Give all rights of created DB to use:

GRANT ALL PRIVILEGES ON yourdb.* TO 'youruser'@'localhost';
FLUSH PRIVILEGES;
exit;

Note: Replace yourdb with the database name you want to give, whereas the youruser with the username and yourpassword with the password you want to assign.

6. Download and Install Nextcloud on AlmaLinux 8

Visit the official website of NextCloud and then download it. Right-click on the Download button and copy the link address.

Download Nextcloud for Rocky Linux

paste the link with wget

wget paste-link

Example:

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

unzip the file:

unzip latest.zip

Move the extracted file to /var/www/html/ directory

sudo mv nextcloud/ /var/www/html/

Create a data folder to store uploaded data in Nextcloud

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

Now, give the Nextcloud permission to Apache user:

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

7. Create Apache VirtualHost file for NextCloud

Let’s create an Apache configuration file for NextCloud, to serve the file in case you are using the domain name or multiple websites are running on the same server.

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

Paste the following lines:

Note: Don’t forget to replace cloud.example.com with the domain name you want to use. If you don’t have any then leave it as it is.

<VirtualHost *:80>

ServerName cloud.example.com
ServerAdmin [email protected]

DocumentRoot /var/www/html/nextcloud

<directory /var/www/html/nextcloud>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
</directory>

</VirtualHost>

Restart the Apache web server and set SELinux policies:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html(/.*)?"
sudo sudo restorecon -Rv /var/www/html
sudo systemctl restart httpd

8. Open port in Firewall

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

9. Access NextCloud Web Interface

Once all the above steps are completed you are ready to access the web interface for setting up NextCloud further on your AlmaLinux 8 system.

Open your browser that can access the domain or IP address of the server where you have installed NextCloud. After that point to the Ip or domain:

http://your-server-ip-address
or
http://your-domain.com

Create Admin user and enter Database Details

The first page will ask you to create an Admin user and after that select MySQL/MariaDB as Database. There enter the details of the Database you have created.

After that click on the Finish button.

Create Admin user and Database details to cloud
Nextcloud setup using command on AlmaLinux
NextCloud install AlmaLinux 8

10. How to Update or Upgrade

In the future if you want to upgrade your NextCloud using the command, easily, then here is the command:

Edit php.ini

sudo nano /etc/php.ini

Scroll to the end of the file:

--define apc.enable_cli=1

Save the file using Ctrl+O, hit the Enter key, and then press Ctrl+X

Once you have added 

sudo -u apache php --define apc.enable_cli=1 /var/www/html/nextcloud/updater/updater.phar
How to upgrade or Update Nextcloud using command line

11. Set Let’s Encrypt SSL for NextCloud

Those who also want to set SSL certificate need to run the following commands:

Note: Make sure in your Domain DNS “A” record is pointing to the Ip-address where you have installed NextCloud.

sudo dnf -y install certbot mod_ssl
sudo certbot certonly --standalone -d cloud.example.com --preferred-challenges http --agree-tos -n -m [email protected] --keep-until-expiring

Once the SSL certificate has been issued successfully edit your existing Apache Configuration:

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

Delete existing configuration and add the following one. And don’t forget to replace the cloud.example.com with the domain name you want to use access NextCloud.

<VirtualHost *:80>
ServerName files.example.com
ServerAdmin [email protected]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<IfModule mod_ssl.c>

<VirtualHost *:443>

ServerName cloud.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/nextcloud

<directory /var/www/html/nextcloud>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
</directory>

SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/cloud.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cloud.example.com/privkey.pem

</VirtualHost>
</IfModule>

Save the file by pressing Ctlr+O, hit the Enter key, and then exit the same using Ctrl+X.

Restart Apache webserver:

sudo systemctl restart httpd

Conclusion

In this way, we can install NextCloud on AlmaLinux or in any Redhat-based system such as CentOS, Oracle Linux… Although it is a good way to set up your cloud to access files remotely, a few disadvantages are always there. Such as the user will be responsible for maintenance, security, and settings including hardware.

Installing and setting up your own Nextcloud on a Linux VPS takes about an hour – and is also doable for Linux newbies. And what if you hear about any security breaches and scandals from the usual cloud providers in the future? Then you can build your own cloud using Nextcloud; it can improve OwnCloud’s offering in several ways. It’s important to weigh the pros and cons of the open-source and commercial options when choosing a storage solution. Nextcloud ‘s open-source file-sharing tool is a viable, free, and attractive option for many individuals and businesses.

Other Articles:

Enable Minimize & Maximize buttons on Almalinux or Rocky Linux
How to Install WordPress on AlmaLinux 8 | Rocky Linux 8
Install Nextcloud Client on Debian 11 Bullseye Linux
How to Install Cockpit on Ubuntu 22.04 | 20.04 LTS
How to install FileZilla client on Rocky Linux

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.