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).
Prerequisites
To install Nextcloud you will also need the following software:
Apache Web Server. To install Apache you can refer to our Apache web server installation guide.
MySQL. You can install MySQL by following our guide
PHP. Follow instructions from our PHP installation guides to install PHP on your server:
- [PHP installation guide for CentOS 7.
- [PHP installation guide for AlmaLinux 8.]
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"):
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 "admin@domain.com" to your actual email:
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 "admin@domain.com" to the actual hostname and email:
export DOMAIN="your_server_hostname"
export EMAIL="admin@domain.com"
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 "admin@domain.com" to your actual hostname and email):
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 "admin@domain.com" to your actual hostname and email address:
certbot --apache --agree-tos --no-eff-email --redirect --hsts --staple-ocsp --email admin@domain.com -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:
[](https://your_server_hostname)
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!