frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

[CentOS 7/AlmaLinux 8] How to install Nextcloud on CentOS 7 and AlmaLinux 8

MichailMichail Moderator
edited September 2 in Web Applications

Introduction

Nextcloud is an open-source program with which you can organize your own cloud storage.

An important feature of using Nextcloud as a cloud storage is data security. The information is stored on a server under your control, and you yourself can set up protection and differentiate access rights.

In addition, there are over a hundred applications that can be integrated and used with Nextcloud.

In this tutorial, we will show how to install Nextcloud on RedHat based distributions (CentOS 7, AlmaLinux 8).

WARNING

CentOS 7 reached the EOL June 30, 2024:

https://blog.centos.org/2023/04/end-dates-are-coming-for-centos-stream-8-and-centos-linux-7/

Because of this, you may encounter some repository issues. We recommend that you reinstall another OS that has not yet reached EOL.

If you are using CentOS 7 and encounter a mirror issue, please check out this guide to resolve the problem.

Prerequisites

To install Nextcloud you will also need the following software:

Installation guide

Step for AlmaLinux 8 only: Import GPG key repository

This step is for AlmaLinux 8 only. Skip this step if you are installing Nextcloud on CentOS 7.

Run the following command to install updated GPG keys on AlmaLinux 8:

rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux

1. Update the system

To update system, run the following command:

yum update

2. Enabling extensions

You also need to enable some extensions.

On CentOS 7 run the following command:

yum -y install mod_ssl 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

On AlmaLinux 8 run this command:

yum install php-xml php-cgi php-cli php-mysql php-mbstring php-gd php-curl php-zip wget zip

3. Downloading installation files

In this guide, we are installing Nextcloud version 28, but you can install any other version. To select the version you want, go to the nextcloud page and copy the link of the selected version (click the selected version and select "copy link"):

https://download.nextcloud.com/server/releases/

Then run the command wget with this link as in this example:

wget https://download.nextcloud.com/server/releases/nextcloud-28.0.3.zip

4. Unzip the downloaded file

To unpack the downloaded archive, you first need to install the 'unzip'(if you have not already done so):

yum install unzip

Once 'unzip' installed, you can extract installation files by running this command:

unzip nextcloud-28.0.3.zip

Move extracted folder to the /var/www/html/

mv nextcloud/ /var/www/html/

Create directory to store Nextcloud files:

mkdir /var/www/html/nextcloud/data

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

Finally, give the apache user the required ownership:

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

5. Create configuration file for Nextcloud

Create Apache configuration file for Nextcloud by running the following command:

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

In this file, enter the following lines and make sure to change "serverhostname" to your server hostname and "[email protected]" to your actual email:

<VirtualHost *:80>
ServerName serverhostname
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>

After that, restart Apache web server:

systemctl restart httpd

6. Open ports

Allow ports 80 (http) and 443 (https) in iptables by running the following commands:

iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT

iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT

Then save the changes:

iptables-save

At this point, Nextcloud is already enabled on your server and you can open it by entering your server's hostname as the URL in your web browser (http://your_server_hostname). However, the connection is not secure (http), so if you want to access Nextcloud via https, follow next steps.

Please note: If firewalld enabled on your server, you will need to allow http and https on it as well:

firewall-cmd --permanent --add-service=http

firewall-cmd --permanent --add-service=https

Then reload firewalld:

firewall-cmd --reload

7. Configure Nextcloud With Let’s Encrypt SSL on CentOS 7

This step is for CentOS 7 only. Proceed to the next step if you want to secure your Nextcloud connection in AlmaLinux 8.

First, install EPEL release and certbot:

yum -y install epel-release

yum -y install certbot

Then, run the following commands and make sure to change "your_server_hostname" and "[email protected]" to the actual hostname and email:

export DOMAIN="your_server_hostname"
export EMAIL="[email protected]"
certbot certonly --standalone -d $DOMAIN --preferred-challenges http --agree-tos -n -m $EMAIL --keep-until-expiring

Then open the Nextcloud configuration file:

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

And paste these lines (change "your_server_hostname" and "[email protected]" to your actual hostname and email):

<VirtualHost *:80>

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

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName your_server_hostname
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/your_server_hostname/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/your_server_hostname/privkey.pem
</VirtualHost>
</IfModule>

After that restart the Apache:

systemctl restart httpd

8. Configure Nextcloud With Let’s Encrypt SSL on AlmaLinux 8

This step is for AlmaLinux 8.

First, install Certbot:

dnf install certbot python3-certbot-apache mod_ssl

Then run the following command to enable self-signed SSL/TLS certificates for localhost:

openssl req -newkey rsa:2048 -nodes -keyout /etc/pki/tls/private/localhost.key -x509 -days 365 -out /etc/pki/tls/certs/localhost.crt

Finally, run the last command to generate a certificate for your server hostname. Make sure to change your_server_hostname" and "[email protected]" to your actual hostname and email address:

certbot --apache --agree-tos --no-eff-email --redirect --hsts --staple-ocsp --email [email protected] -d your_server_hostname

9. Complete Nextcloud installation

Now you can navigate to your Nextcloud by visiting the hostname of your server in a web browser:

You should see the following page:

To complete installation, you need to create a Nextcloud user. For that, enter the new user username and password:

Aftetr that click on "MySQL/MariaDB" and enter the MySQL username, password and database name (you need to have created database to run Nextcloud). Click "Install" to complete the installation.

That's all. Now, you can manage your files via Nextcloud!

Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch