CentOSRHEL Based

How To Install Nextcloud on CentOS Stream 10

Install Nextcloud on CentOS Stream 10

How To Install Nextcloud on CentOS Stream 10 is a frequently searched topic for administrators aiming to build a secure, self-hosted file sharing and collaboration platform. Nextcloud offers powerful features such as document editing and syncing, calendar management, app integrations, and robust security options. Below is an extensive guide outlining the step-by-step procedure for installing Nextcloud on CentOS Stream 10 with a LAMP (Linux, Apache, MariaDB/MySQL, PHP) stack, while keeping essential considerations like SELinux, SSL/TLS, and performance tuning in mind.

Introduction

Nextcloud is a versatile cloud solution that allows administrators to maintain full control over their data by hosting documents, calendars, contacts, and more on their own infrastructure. It provides the flexibility to manage sensitive files, share them with collaborators, and integrate productivity apps. CentOS Stream 10, as a rolling-release distribution aligned with Red Hat Enterprise Linux (RHEL) development, offers updated packages and a secure base for hosting applications. Combining Nextcloud with CentOS Stream 10 ensures stability, performance, and a balance of modern software features.

By installing Nextcloud on CentOS Stream 10, organizations benefit from rapid security patches and upstream bug fixes, while enjoying the reliability of an enterprise-grade operating system. This guide dives into system prerequisites, package installation, configuration details, troubleshooting tips, and performance tuning. Following these sections carefully helps ensure that Nextcloud is properly set up, secure, and running optimally.

System Requirements

Hardware Requirements:
• A server (physical or virtual) running CentOS Stream 10.
• At least 2 CPU cores (although Nextcloud can run on a single core, more CPU power improves responsiveness).
• Sufficient storage space for user data. Ideally, keep the operating system partition separate from data storage.
• A minimum of 128MB of RAM per PHP process, though 512MB per process is recommended (for example, 2GB system memory for a modest installation).

Software Requirements:
• Apache HTTP Server (suggested for compatibility with Nextcloud).
• MariaDB or MySQL (InnoDB engine for Nextcloud).
• PHP 7.4+ or 8.x (with modules like php-gd, php-mbstring, php-xml, php-zip, and others).
• Proper firewall settings (e.g., firewalld) to allow HTTP/HTTPS traffic.
• Optional: SSL/TLS certificate (self-signed or from a valid CA) for secure HTTPS connections.

Pre-Setup Checks:
• Validate available system resources by running commands like df -h (for disk space) and free -h (for RAM).
• Ensure network connectivity; test with commands such as ping or curl on important repositories.
• Confirm system is updated and has the latest security patches before the Nextcloud installation.

Pre-Installation Setup

1. Update the System
Keeping packages current reduces security risks. Run:

sudo dnf update -y

This ensures CentOS Stream 10 is up to date and ready to install server components.

2. Install Development Tools and Wget
Development tools and utilities like wget are helpful when building or fetching software:

sudo dnf groupinstall "Development Tools" -y
sudo dnf install wget unzip -y

These packages enable additional compilation or diagnostic capabilities.

3. Configure SELinux
CentOS Stream 10 typically comes with SELinux enabled by default. Nextcloud requires certain SELinux contexts and file privileges. One option is setting SELinux to permissive mode if encountering permissions issues. However, keeping SELinux in enforcing mode with the correct policies is recommended for security:

sudo vi /etc/selinux/config
# Set this to 'permissive' or consider using policies:
SELINUX=enforcing

After editing, reboot the server to apply changes. Administrators can also employ semanage fcontext commands to allow Apache to write to Nextcloud directories.

4. Configure Firewall
Open ports 80 (HTTP) and 443 (HTTPS) to enable external access:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

The firewall-cmd commands ensure Apache-based Nextcloud is accessible from the internet.

5. Install the LAMP Stack
Nextcloud depends on a web server, database server, and PHP. Begin by installing Apache:

sudo dnf install httpd httpd-tools -y

Enable and start Apache:

sudo systemctl enable httpd
sudo systemctl start httpd

Now install MariaDB (or MySQL) and PHP along with extensions Nextcloud requires:

sudo dnf install mariadb-server \
   php php-mysqlnd php-pdo php-gd php-mbstring \
   php-xml php-zip php-curl php-json php-intl

Activate and start MariaDB:

sudo systemctl enable mariadb
sudo systemctl start mariadb

Database Configuration

Nextcloud requires a dedicated database and user. Log in to the MariaDB shell:

sudo mysql -u root

For stronger security, run the automated secure installation script:

sudo mysql_secure_installation

Configure a strong root password and apply recommended security settings. Then create a Nextcloud database and user (replace strong_password with a secure, unique password):

CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

The commands above produce a dedicated database named nextcloud and a user nextclouduser with restricted privileges. Using the InnoDB storage engine is critical, as Nextcloud does not support MyISAM. Verify innodb_file_per_table is enabled in /etc/my.cnf for optimal performance. If binary logging is in use, ensure it is correctly configured (ideally, BINLOG_FORMAT=ROW).

Nextcloud Installation

1. Download Nextcloud
Obtain the latest Nextcloud archive from the official website:

cd /var/www
sudo wget https://download.nextcloud.com/server/releases/latest.zip

Check for the newest version on Nextcloud’s official site if needed. After downloading, unzip the package:

sudo unzip latest.zip

This process creates a nextcloud directory in /var/www.

2. Set Permissions
To ensure Apache can read and write properly, set appropriate ownership:

sudo chown -R apache:apache /var/www/nextcloud
sudo chmod -R 755 /var/www/nextcloud

Apache (the apache user) needs these rights to handle file uploads, caching, and Nextcloud’s data directory.

3. Configure Apache Virtual Host
Create a new Apache configuration file like:

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

Include:

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /var/www/nextcloud

    <Directory /var/www/nextcloud>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
        <FilesMatch \.(php|phar)$>
            SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
        </FilesMatch>
    </Directory>

    ErrorLog /var/log/httpd/nextcloud_error.log
    CustomLog /var/log/httpd/nextcloud_access.log combined
</VirtualHost>

Adjust ServerName to match your domain or server hostname. Then restart Apache:

sudo systemctl restart httpd

PHP Configuration

Nextcloud performs best with specific PHP settings. Edit php.ini or a .conf file under /etc/php.d to set recommended values:

  • memory_limit: Increase to at least 512M or 1G, particularly if handling large files.
  • upload_max_filesize: Adjust to accommodate bigger uploads, for example 2G.
  • post_max_size: Match upload_max_filesize to avoid misunderstandings in file uploads.
  • max_execution_time: Raise to 3600 if large uploads or intense operations are expected.
  • date.timezone: Align with your local timezone (e.g., America/New_York).

Example configuration snippet:

sudo nano /etc/php.d/nextcloud.ini

memory_limit = 1G
upload_max_filesize = 2G
post_max_size = 2G
max_execution_time = 3600
date.timezone = "America/New_York"

Restart PHP-FPM and Apache:

sudo systemctl restart php-fpm
sudo systemctl restart httpd

These values help prevent timeouts and memory errors, especially when many users are active or uploading large files simultaneously.

Security Configurations

1. Enable HTTPS/SSL
Secure connections with an SSL certificate. Acquire a free Let’s Encrypt certificate or create a self-signed certificate:

sudo dnf install certbot python3-certbot-apache
sudo certbot --apache

Follow the prompts to generate certificates and configure your Apache virtual host for HTTPS. SSL ensures data confidentiality.

2. Adjust Security Headers
To protect against cross-site scripting (XSS) and clickjacking, add headers in nextcloud.conf:

Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"

Ensure mod_headers is enabled.

3. File Permissions Hardening
Set the nextcloud directory to read-only for everyone except Apache, except for data and config subdirectories. Strict permissions reduce unauthorized modifications.

4. Redis Cache (Optional)
For improved performance and transaction locking, install Redis:

sudo dnf install redis
sudo systemctl enable redis
sudo systemctl start redis

Then configure Nextcloud to use Redis for file locking by editing config.php accordingly.

Post-Installation Steps

Access Nextcloud by opening a browser and navigating to:

http://your-domain.com

(or https://your-domain.com if SSL is properly configured). At the initial prompt, specify an admin username/password, and define the Nextcloud data folder path (/var/www/nextcloud/data by default). Provide the database credentials for nextclouduser and the previously configured database name (nextcloud).

Install Nextcloud on CentOS Stream 10

Once configured, Nextcloud completes installation and displays the main dashboard. Explore recommended apps for expanding functionality (like collaboration tools or calendars). At a minimum, run initial security checks:

sudo -u apache php /var/www/nextcloud/occ security:certificates

and confirm everything is operating correctly. This ensures the new installation meets baseline security standards.

Performance Optimization

1. Caching Setup: Integrate Redis or APCu for better performance. For a small environment, APCu can function as a local memory cache. Add entries in the config.php:

'memcache.local' => '\\OC\\Memcache\\APCu',
'memcache.locking' => '\\OC\\Memcache\\Redis',

2. Database Tuning: Configure innodb_buffer_pool_size in /etc/my.cnf to leverage available memory. Balancing memory usage is important to prevent swapping. Tables with frequent reads and writes benefit from a healthy buffer pool size.

3. Apache Tweaks: For high-traffic sites, consider using mpm_event with php-fpm. Tune MaxRequestWorkers and ServerLimit to handle concurrency while avoiding resource exhaustion.

4. Background Jobs: Configure a cron job to handle tasks like file version cleanup:

sudo -u apache crontab -e
# Add:
*/5 * * * * php -f /var/www/nextcloud/cron.php

Regularly running cron tasks maintains system performance over time.

Troubleshooting Guide

1. Permission Issues: If encountering 403 or 500 errors when visiting Nextcloud pages, verify Apache’s ownership and SELinux contexts. Temporarily switch to permissive mode (setenforce 0) to diagnose SELinux blocks. Then apply correct SELinux rules.

2. Database Connection: “Cannot connect to database” errors are often due to invalid credentials or missing privileges. Confirm nextclouduser can access the nextcloud database from localhost with the correct password in /var/www/nextcloud/config/config.php.

3. Missing PHP Modules: If Nextcloud warns about missing modules like gd or mbstring, install them with dnf install php-gd php-mbstring, then reload PHP and Apache.

4. Internal Server Error (HTTP 500): Check /var/log/httpd/error_log and /var/www/nextcloud/data/nextcloud.log for detailed messages. Often, it’s a file permission misconfiguration or missing extensions.

Maintenance and Backup

1. Regular Backups: Create scheduled backups of the Nextcloud data folder (/var/www/nextcloud/data) and the database. Tools such as rsync or tar help backup files, while mysqldump exports the database for restoration if needed.

2. Applying Updates: Nextcloud offers an in-browser updater, but requires enough PHP memory (at least 256MB). Alternatively, use the command-line updater:

sudo -u apache php /var/www/nextcloud/updater/updater.phar

3. Security Maintenance: Run:

sudo -u apache php /var/www/nextcloud/occ security:scan

Check for vulnerabilities and keep your system patched with dnf update.

4. Performance Monitoring: Monitor resource usage via htop or nmon. Syslog or journald logs provide evidence of potential resource shortages. Adjust caching or memory settings if usage spikes.

Congratulations! You have successfully installed Nextcloud. Thanks for using this tutorial for installing the Nextcloud open-source file hosting on CentOS Stream 10 system. For additional or useful information, we recommend you check the official Nextcloud website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button