KB450264 – Nextcloud Installation CentOS 7

Last modified: May 31, 2021
You are here:
Estimated reading time: 3 min

Nextcloud Installation Guide

Scope/Description:

Nextcloud requires a standard LAMP web stack (Linux, Apache, SQL, PHP).

This article will walk through the steps to install the LAMP web stack, Nextcloud server, and redis memcaching, on CentOS 7.

Prerequisites:

Steps:

Linux

  • SSH into the server that will be running nextcloud, or use the shell module in the Cockpit UI.
  • Install dependencies
[root@nextcloud~]# yum install -y vim epel-release yum-utils unzip curl wget bash-completion policycoreutils-python mlocate bzip2
  • Ensure system is up to date
[root@nextcloud~]# yum update -y

Apache (httpd)

  • Install Apache  webserver (httpd)
[root@nextcloud~]# yum install httpd -y
  • Create virtualhost config file for nextcloud
cat <<EOF >> /etc/httpd/conf.d/nextcloud.conf
<VirtualHost *:80>
  DocumentRoot /var/www/html/nextcloud/
  ServerName your.server.com

 <Directory /var/www/html/nextcloud/>
   Require all granted
   AllowOverride All
   Options FollowSymLinks MultiViews

   <IfModule mod_dav.c>
     Dav off
   </IfModule>

  </Directory>
</VirtualHost>
EOF
  • Start and enable the httpd service
[root@nextcloud ~]# systemctl enable --now httpd

PHP

  • Configure repository for php7
[root@nextcloud ~]# yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@nextcloud ~]# yum-config-manager --enable remi-php74
[root@nextcloud ~]# dnf module install php:remi-7.4
  • Install required php modules
[root@nextcloud ~]# yum install php php-dom php-mbstring php-gd php-pdo php-json php-xml php-zip php-curl php-pear php-intl php-bcmath php-gmp setroubleshoot-server bzip2 php-pecl-imagick php-smbclient php-ldap

Database (MySQL/MariaDB)

  • Install mariadb on the server
[root@nextcloud ~]# yum install -y mariadb-server php-mysql
  • Start and enable the database service
[root@nextcloud ~]# systemctl enable --now mariadb
  • Harden SQL install, create a root password and answer YES to every question when prompted
[root@nextcloud ~]# mysql_secure_installation
  • Add the following config options to the “[server]” section of /etc/my.cnf.d/server.cnf
skip-name-resolve
innodb_buffer_pool_size = 128M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 64M
tmp_table_size= 64M
max_heap_table_size= 64M
slow-query-log = 1
slow-query-log-file = /var/log/mysql/slow.log
long_query_time = 1
  • Add the following config options to the “[mysqld]” section of /etc/my.cnf.d/server.cnf
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW
innodb_large_prefix=on
innodb_file_format=barracuda
innodb_file_per_table=1
  • Start the MySQL command line. The root password is the one created when running “mysql_secure_installation
[root@nextcloud ~]# mysql -uroot -p
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
  • Create the a user for nextcloud to use. The bolded parts can be changed, it recommended to leave the username as “nextclouduser”. It is strongly reccomended to change the password.
MariaDB [(none)]> CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'password';
  • Create the database for nextcloud. The bolded part can be chnaged, however it is recommended to leave the database name as nextcloud.
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
  • Grant all privileges on nextcloud database to the user created above.
MariaDB [(none)]> GRANT ALL PRIVILEGES on nextcloud.* to 'nextclouduser'@'localhost';
MariaDB [(none)]> FLUSH privileges;
  • Quit mariadb cli
MariaDB [(none)]> quit;
  • Take note of the following you will need to finish the nextcloud setup.
    • dbname:  nextcloud
    • dbuser: nextclouduser
    • dbpassword: password
    • dbhost: localhost

Nextcloud

  • Go to the Nextcloud download page
  • Go to Download for Server > Archive File > Details and download option and copy  the tar.bz2 link. Download onto the nextcloud server
[root@nextcloud ~]# curl -LO https://download.nextcloud.com/server/releases/nextcloud-20.0.4.tar.bz2
  • Untar nextcloud archive
[root@nextcloud ~]# tar -xvf nextcloud-20.0.4.tar.bz2
  • Move nextcloud files to root directory of the server
[root@nextcloud ~]# mv nextcloud/ /var/www/html/
  • Create default data directory for nextcloud
[root@nextcloud ~]# mkdir /var/www/html/nextcloud/data
  • Ensure apache service (webserver) has access to nextcloud
[root@nextcloud ~]# chown -R apache:apache /var/www/html/nextcloud
  • Restart apache
[root@nextcloud ~]# systemctl restart httpd.service
  • Create a firewall rule for access to apache:
[root@nextcloud ~]# firewall-cmd --zone=public --add-service=http --permanent ; firewall-cmd --reload
  • Now point your browser to the nextcloud IP or Hostname

  • Finish the nextcloud setup by creating an admin account, and hook into the database created earlier

  • Nextcloud is now installed, you can log in with the newly created admin account.

Web Caching Service

NextCloud can be very slow if no caching solution is not in place. There are two caching solutions covered:

  • PHP OPcache: a PHP inbuilt cache solution that speeds up scripts execution.
  • Redis server: a fast in-memory key-value store that speeds up everything in NextCloud.
  • Install OPcache
[root@nextcloud ~]# yum install -y php-opcache
  • Add the following to /etc/php.d/10-opcache.ini
; nextcloud optimizations
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
  • Install redis web cache service
[root@nextcloud ~]# yum install redis php-pecl-redis
  • Add the following lines to the bottom of /var/www/html/nextcloud/config/config.php
'memcache.locking' => '\\OC\\Memcache\\Redis',
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.local' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => 'localhost',
'port' => 6379,
'timeout' => 3,
  • Start and enable redis service
[root@nextcloud ~]# systemctl enable --now redis
[root@nextcloud ~]# systemctl restart httpd

Verification:

Troubleshooting:

Was this article helpful?
Dislike 0
Views: 58
Unboxing Racking Storage Drives Cable Setup Power UPS Sizing Remote Access