How to install NextCloud server on Rocky Linux 8

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

What is Nextcloud?

Nextcloud is a free open source cloud software for the encrypted storage of data in a cloud or on your servers. It is client-server software and forked of another open-source known as “OpenCloud”. Also, it is a good alternative to cloud storage like Dropbox, Google Drive, and OneDrive, if someone wants a seld-hosted personal cloud solution.

Cloud storage like Dropbox, Google Drive, and OneDrive are very popular nowadays; one of the reasons is the automatic sync of users’ files to the cloud across different devices, so data is easily accessible and not lost. Well, that facility is also there on Nextcloud.

Although such public cloud storage services are offered by larger companies generally safe and reliable. However, these offers also have disadvantages. They only offer their customers a limited amount of free storage space. If customers need more space to store their data, they have to pay.

NextCloud also offers two-factor authentication to better protect the cloud accounts against unauthorized access. Whereas this personal cloud server can also encrypt data to securely send data remotely, however, to improve the user experience, especially for newcomers, encryption is not enabled by default. Because encryption increases file size by approximately 35%. Further it also comes with Healthcare and HIPAA; GDPR Compliance Kit; Auditing capabilities and File Access Control.

Steps to install NextCloud on Rocky Linux 8

The steps given here will be applicable for other RedHat-based Linux distros such as CentOS, Almalinux, Oracle Linux…

1. Requirements

Rocky Linux 8
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 Rocky Linux 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 Rocky Linux

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 restriction 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 Rocky Linux 8

According to NextCloud, PHP 8.0 is recommended to use. Hence, we go for that because the version via the default repository of Rocky Linux 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 nano /etc/php.ini

Find memory_limit and set the value to 512M

memory_limit = 512M

Save the file: Ctrl+O, hit the Enter key, and then exit: Ctrl+X.

 

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 Rocky Linux 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/nextcloud-23.0.0.zip

unzip the file:

unzip nextcloud-*.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, the 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 Rocky Linux 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

Upload file and documents to NextCloud Server NextCloud installation on Rocky Linux 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/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 systemctl stop httpd
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.

 

Conclusion

In this way, we can install NextCloud on Rocky Linux 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.

Other Articles:

Enable Minimize & Maximize buttons on Almalinux or Rocky Linux
How to install NextCloud on Debian 11 Bullseye Linux
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

1 thought on “How to install NextCloud server on Rocky Linux 8”

  1. I suggest you deactivate SeLinux after installing all the necessary software, then when it comes time to configure, then you deactivate your network, you make your changes for the settings of http, mariadb, php and config.php of nextcloud.
    You reactivate SeLinux in enforcing mode and file labeling then you do a reboot.
    I haven’t seen how you do to secure your site with Let’s Encrypt, neither fail2ban nor firewallID.
    Your tutorial is incomplete
    Good luck

    Reply

Leave a Comment

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