How to install Nextcloud on CentOS 8
Nextcloud is open source software to create a cloud storage service like Dropbox or Google Drive but can be installed on your own server.
Nextcloud server supports a variety of major Linux distributions, such as Ubuntu, Debian, Red Hat, CentOS, SUSE, and openSUSE. Meanwhile, the Nextcloud client is available for desktop versions (Windows, macOS, Linux) and mobile versions (Android, iOS, Windows Phone).
0. System Requirements
Nextcloud server requires a system with the following specifications:
Operating System
- Ubuntu 18.04 LTS (recommended)
- Red Hat Enterprise Linux 8 (recommended)
- Debian 10
- SUSE Linux Enterprise Server 15
- openSUSE Leap 42.1+
- CentOS 8
Database
- MySQL 5.7+ atau MariaDB 10.2+ (recommended)
- Oracle Database 11g
- PostgreSQL 9/10/11
- SQLite (only recommended for testing)
Web Server
- Apache 2.4 dengan mod_php atau php-fpm (recommended)
- nginx dengan php-fpm
PHP Runtime
- 7.2
- 7.3 (recommended)
- 7.4 (recommended)
Memory
The memory required depends on the number of users, apps, files and server activity.
Nextcloud requires a minimum of 128MB of RAM, a minimum of 512MB of RAM is recommended.
1. Setting up CentOS 8 Server
This tutorial uses the CentOS 8 VPS at UpCloud with 1 core CPU specs, 1GB RAM, and 25GB storage.
SSH login to server, update system.
1 | dnf update -y |
Install langpack to resolve the error message Failed to set locale, defaulting to C.UTF-8.
1 | dnf install langpacks-en glibc-all-langpacks -y |
Install EPEL repository.
1 | dnf install epel-release -y |
Install the support package.
1 | dnf install unzip curl wget bash-completion mlocate policycoreutils-python-utils -y |
2. Connect Domain with Server
This tutorial uses the subdomain cloud.defnex.com. In the DNS manager, create a A record with hostname cloud.defnex.com and server IP address.
ping the domain to test if it is connected to the server.
1 2 3 4 5 6 | ping cloud.defnex.com PING cloud.defnex.com (94.237.74.88) 56(84) bytes of data. 64 bytes from 94-237-74-88.sg-sin1.upcloud.host (94.237.74.88): icmp_seq=1 ttl=53 time=25.0 ms 64 bytes from 94-237-74-88.sg-sin1.upcloud.host (94.237.74.88): icmp_seq=2 ttl=53 time=29.1 ms 64 bytes from 94-237-74-88.sg-sin1.upcloud.host (94.237.74.88): icmp_seq=3 ttl=53 time=34.6 ms |
3. Install Apache Web Server
Install Apache web server.
1 | dnf install httpd -y |
Activate and run the httpd service.
1 2 3 | systemctl enable --now httpd systemctl start httpd systemctl status httpd |
Allow http protocol in firewall
1 2 3 | firewall-cmd --add-service=http --permanent firewall-cmd --reload firewall-cmd --list-services |
Apache virtual host
Create an Apache virtual host configuration file for the domain/subdomain.
1 2 | cd /etc/httpd/conf.d nano cloud.defnex.com.conf |
The contents of the virtual host configuration file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <VirtualHost *:80> ServerName cloud.defnex.com DocumentRoot /var/www/cloud.defnex.com <Directory /var/www/cloud.defnex.com> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /var/www/cloud.defnex.com SetEnv HTTP_HOME /var/www/cloud.defnex.com </Directory> ErrorLog /var/log/httpd/cloud.defnex.com_error.log CustomLog /var/log/httpd/cloud.defnex.com_access.log combined </VirtualHost> |
Create a document root directory.
1 2 | cd /var/www mkdir cloud.defnex.com |
Create a index.html file for testing virtual hosts.
1 2 | cd cloud.defnex.com echo "cloud.defnex.com" > index.html |
Testing Apache configuration, the result is Syntax OK.
1 2 3 | apachectl -t Syntax OK |
Restart httpd service.
1 2 | systemctl restart httpd systemctl status httpd |
Browse http://cloud.defnex.com.
4. Install SSL
Install Certbot Let’s Encrypt.
1 | dnf install certbot python3-certbot-apache -y |
Disable virtual host default SSL configuration.
1 2 3 | cd /etc/httpd/conf.d mv ssl.conf ssl.conf.off systemctl restart httpd |
Request an SSL certificate for the subdomain cloud.defnex.com.
1 | certbot --apache -d cloud.defnex.com |
Enter the requested information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): address@email.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: N |
SSL installed successfully.
1 | Congratulations! You have successfully enabled https://cloud.defnex.com |
Allow https protocol in firewall
1 2 3 | firewall-cmd --add-service=https --permanent firewall-cmd --reload firewall-cmd --list-services |
Browse https://cloud.defnex.com.
5. Install PHP
The PHP version available in the default CentOS 8 repository is PHP 7.2. To be able to run PHP 7.4 install the REMI repository.
1 | dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y |
Enable PHP 7.4 stream module.
1 | dnf module enable php:remi-7.4 -y |
Install PHP 7.4 along with the extensions needed by the Nextcloud server.
1 | dnf install php74 php74-php php74-php-common php74-php-fpm php74-php-cli php74-php-gd php74-php-mbstring php74-php-intl php74-php-pecl-apcu php74-php-mysqlnd php74-php-opcache php74-php-json php74-php-zip -y |
Activate and run the PHP-FPM service.
1 2 3 | systemctl enable --now php74-php-fpm systemctl start php74-php-fpm systemctl status php74-php-fpm |
Restart httpd service.
1 | systemctl restart httpd |
Create a info.php file for PHP tests.
1 2 | cd /var/www/cloud.defnex.com echo "<?php phpinfo(); ?>" > info.php |
Browse https://cloud.defnex.com/info.php.
If PHP is running properly, delete the info.php and index.html files.
1 | rm -f info.php index.html |
6. Install MariaDB Database
Install MariaDB database.
1 | dnf install mariadb-server -y |
Activate and run the MariaDB service.
1 2 3 | systemctl enable mariadb systemctl start mariadb systemctl status mariadb |
Secure MariaDB installation.
1 | mysql_secure_installation |
Answer the question.
1 2 3 4 5 6 | Enter current password for root (enter for none): ENTER Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y |
Login to MariaDB.
1 | mysql -u root -p |
Create a database and user for Nextcloud.
1 2 3 4 5 | CREATE DATABASE nextcloud; CREATE USER 'usrnxtcld'@'localhost' IDENTIFIED BY 'thesecret'; GRANT ALL PRIVILEGES ON nextcloud.* TO 'usrnxtcld'@'localhost'; FLUSH PRIVILEGES; EXIT; |
7. Install Nextcloud Server
Download Nextcloud server, extract it, and copy it to the document root directory.
1 2 3 | wget https://download.nextcloud.com/server/releases/nextcloud-19.0.1.zip unzip nextcloud-19.0.1.zip cp -R nextcloud/* /var/www/cloud.defnex.com |
Change document root ownership and permissions.
1 2 3 | cd /var/www chown -R apache:apache cloud.defnex.com chmod -R 755 cloud.defnex.com |
Check if SELinux is active.
1 2 3 | getenforce Enforcing |
If SELinux is enabled (Enforcing), restore the context document root as a web file.
1 2 | semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/cloud.defnex.com(/.*)?' restorecon -Rv '/var/www/cloud.defnex.com' |
Browse https://cloud.defnex.com to install Nextcloud.
Create an admin account.
Database configuration, click Storage & database, click MySQL/MariaDB. Enter the username, password and database.
Check Install recommended apps if you want to install Calendar, Contacts, Talk, Mail, & Collaborative editing applications.
Finally, click Finish setup.
Nextcloud has finished installing.
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin