AlmaLinuxRHEL Based

How To Install NextCloud on AlmaLinux 10

Install NextCloud on AlmaLinux 10

NextCloud stands as one of the most robust open-source cloud storage solutions available today, offering enterprise-grade features for organizations and individuals seeking complete control over their data. This comprehensive guide walks you through installing NextCloud on AlmaLinux 10, leveraging the stability and security of Red Hat Enterprise Linux (RHEL) compatibility.

Self-hosting your cloud storage solution provides unmatched benefits including enhanced data privacy, complete administrative control, and freedom from vendor lock-in scenarios. AlmaLinux 10 serves as an excellent foundation for NextCloud deployment due to its enterprise-grade stability, long-term support lifecycle, and comprehensive security features.

Throughout this tutorial, you’ll build a complete LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack optimized specifically for NextCloud performance. The installation process covers every essential component from initial system preparation through post-deployment security hardening.

This guide targets system administrators, DevOps engineers, and Linux enthusiasts with basic command-line experience. Upon completion, you’ll have a fully functional NextCloud instance ready for production use, complete with proper security configurations and performance optimizations.

Prerequisites and System Requirements

Before beginning the NextCloud installation process, ensure your AlmaLinux 10 server meets the following minimum requirements. A fresh AlmaLinux 10 installation provides the cleanest foundation for this deployment.

Hardware specifications require at least 512MB RAM per concurrent user, though 2GB RAM is recommended for optimal performance. The 64-bit CPU architecture is mandatory for NextCloud compatibility. Storage requirements depend on your intended usage, but allocate at least 10GB for the base system plus additional space for user data.

Network requirements include a stable internet connection for downloading packages and updates. While not mandatory, having a static IP address or registered domain name simplifies long-term maintenance and SSL certificate management.

Access privileges necessitate root access or a user account with sudo privileges. Basic command-line familiarity is essential, as this installation primarily uses terminal commands. Understanding of Linux file permissions and basic networking concepts will prove beneficial throughout the process.

SELinux considerations are particularly important on AlmaLinux 10, as Security-Enhanced Linux runs in enforcing mode by default. This guide includes specific SELinux configuration steps to ensure NextCloud functions properly while maintaining system security.

Additional tools including a text editor (nano, vim, or emacs) and basic troubleshooting utilities should be available on your system.

System Preparation and Updates

Initial system preparation ensures your AlmaLinux 10 server has the latest security patches and required utilities. Begin by updating all system packages to their latest versions.

Execute the following command to update your system:

sudo dnf update -y

This process may take several minutes depending on your internet connection and the number of available updates. The system might require a reboot if kernel updates are installed.

Install essential utilities that will be needed throughout the installation process:

sudo dnf install -y unzip wget curl nano firewall-cmd

Verify your AlmaLinux 10 installation by checking the system version:

cat /etc/almalinux-release

Confirm adequate disk space is available for the installation:

df -h /var/www/

Ensure at least 5GB of free space in the /var/www/ directory for NextCloud files and initial data storage.

Test network connectivity to verify package repositories are accessible:

ping -c 4 google.com

If SELinux troubleshooting tools aren’t already installed, add them now:

sudo dnf install -y setroubleshoot-server policycoreutils-python-utils

These preparations establish a solid foundation for the subsequent installation steps.

Installing Apache Web Server

Apache HTTP Server serves as the web server foundation for your NextCloud installation. AlmaLinux 10 repositories include the latest stable Apache version optimized for enterprise deployments.

Install Apache using the following command:

sudo dnf install -y httpd httpd-tools

Start the Apache service and configure it to launch automatically at system boot:

sudo systemctl start httpd
sudo systemctl enable httpd

Verify Apache is running correctly:

sudo systemctl status httpd

The status output should display “active (running)” indicating successful startup.

Configure the firewall to allow HTTP and HTTPS traffic:

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

Test your Apache installation by opening a web browser and navigating to your server’s IP address. You should see the default AlmaLinux Apache test page.

Create the directory structure for NextCloud:

sudo mkdir -p /var/www/html/nextcloud

Configure basic Apache security settings by editing the main configuration file:

sudo nano /etc/httpd/conf/httpd.conf

Locate the “ServerTokens” directive and ensure it’s set to “Prod” to minimize information disclosure:

ServerTokens Prod

Add the following security headers to enhance protection:

Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"

Restart Apache to apply the configuration changes:

sudo systemctl restart httpd

Installing and Configuring PHP 8.4

PHP 8.4 provides the runtime environment for NextCloud, offering improved performance and security features. AlmaLinux 10 includes PHP 8.4 in its default repositories, ensuring compatibility and optimal performance.

Install PHP and essential modules required by NextCloud:

sudo dnf install -y php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-opcache php-intl php-ldap

Configure PHP settings for optimal NextCloud performance. Edit the main PHP configuration file:

sudo nano /etc/php.ini

Modify the following directives to accommodate NextCloud’s requirements:

memory_limit = 512M
upload_max_filesize = 512M
post_max_size = 512M
max_execution_time = 300
max_input_time = 300
date.timezone = "UTC"

Configure PHP-FPM for improved performance:

sudo nano /etc/php-fpm.d/www.conf

Adjust the following settings:

user = apache
group = apache
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

Enable OPcache for significant performance improvements:

sudo nano /etc/php.d/10-opcache.ini

Configure OPcache settings:

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
opcache.fast_shutdown=1

Start and enable PHP-FPM:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Verify PHP installation by creating a test file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Access http://your-server-ip/info.php to confirm PHP is working correctly. Remove this file after verification for security purposes.

Restart Apache to ensure PHP integration:

sudo systemctl restart httpd

Installing and Configuring MariaDB

MariaDB serves as the database backend for NextCloud, providing reliable data storage and retrieval capabilities. AlmaLinux 10 includes MariaDB 10.11, which offers excellent performance and compatibility with NextCloud.

Install MariaDB server and client packages:

sudo dnf install -y mariadb mariadb-server mariadb-devel

Start the MariaDB service and enable automatic startup:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure your MariaDB installation by running the security script:

sudo mysql_secure_installation

Follow the prompts to:

  • Set a strong root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database
  • Reload privilege tables

Log into MariaDB as the root user:

mysql -u root -p

Create a dedicated database for NextCloud:

CREATE DATABASE nextcloud_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Create a database user with appropriate privileges:

CREATE USER 'nextcloud_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON nextcloud_db.* TO 'nextcloud_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Configure MariaDB for optimal NextCloud performance by editing the configuration file:

sudo nano /etc/my.cnf.d/nextcloud.cnf

Add the following optimization settings:

[mysqld]
innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
query_cache_type = 1
query_cache_size = 16M
tmp_table_size = 32M
max_heap_table_size = 32M
max_connections = 500
thread_cache_size = 50
open_files_limit = 65535
table_definition_cache = 4096
table_open_cache = 4096

Restart MariaDB to apply the configuration changes:

sudo systemctl restart mariadb

Verify database connectivity:

mysql -u nextcloud_user -p nextcloud_db

Test the connection and exit when successful.

Downloading and Installing NextCloud

NextCloud installation requires downloading the latest stable release and configuring proper file permissions. This section covers obtaining NextCloud files and preparing them for web-based installation.

Navigate to the web directory:

cd /tmp

Download the latest NextCloud release using wget command:

wget https://download.nextcloud.com/server/releases/latest.zip

Verify the download completed successfully by checking the file size:

ls -lh latest.zip

Extract the NextCloud archive:

sudo unzip latest.zip -d /var/www/html/

Create the NextCloud data directory outside the web root for security:

sudo mkdir -p /var/www/nextcloud-data

Set proper ownership for all NextCloud files:

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

Configure secure file permissions:

sudo find /var/www/html/nextcloud/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/nextcloud/ -type f -exec chmod 644 {} \;
sudo chmod +x /var/www/html/nextcloud/occ

Set special permissions for specific directories:

sudo chmod 775 /var/www/html/nextcloud/config/
sudo chmod 775 /var/www/html/nextcloud/apps/
sudo chmod 775 /var/www/nextcloud-data/

Clean up the temporary files:

rm /tmp/latest.zip

Verify the NextCloud files are properly installed:

ls -la /var/www/html/nextcloud/

The directory should contain various NextCloud files and folders including index.php, config/, apps/, and others.

SELinux Configuration

SELinux (Security-Enhanced Linux) provides mandatory access controls that enhance system security. Proper SELinux configuration ensures NextCloud operates correctly while maintaining security policies.

Install SELinux management tools if not already present:

sudo dnf install -y policycoreutils-python-utils setroubleshoot-server

Set appropriate SELinux contexts for NextCloud directories:

sudo semanage fcontext -a -t httpd_exec_t "/var/www/html/nextcloud/occ"
sudo semanage fcontext -a -t httpd_config_t "/var/www/html/nextcloud/config(/.*)?"
sudo semanage fcontext -a -t httpd_config_t "/var/www/nextcloud-data(/.*)?"

Apply the SELinux contexts:

sudo restorecon -Rv /var/www/html/nextcloud/
sudo restorecon -Rv /var/www/nextcloud-data/

Configure SELinux booleans to allow necessary NextCloud operations:

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_execmem 1
sudo setsebool -P httpd_unified 1

Allow Apache to write to NextCloud directories:

sudo semanage fcontext -a -t httpd_rw_content_t "/var/www/html/nextcloud/data(/.*)?"
sudo semanage fcontext -a -t httpd_rw_content_t "/var/www/html/nextcloud/config(/.*)?"
sudo semanage fcontext -a -t httpd_rw_content_t "/var/www/html/nextcloud/apps(/.*)?"
sudo semanage fcontext -a -t httpd_rw_content_t "/var/www/nextcloud-data(/.*)?"

Restore contexts after setting permissions:

sudo restorecon -Rv /var/www/html/nextcloud/
sudo restorecon -Rv /var/www/nextcloud-data/

Verify SELinux contexts are correctly applied:

ls -laZ /var/www/html/nextcloud/

Monitor SELinux for any denial messages:

sudo tail -f /var/log/audit/audit.log | grep nextcloud

If SELinux denials occur, use ausearch and sealert to troubleshoot and create custom policies as needed.

Apache Virtual Host Configuration

Apache virtual host configuration optimizes web server settings specifically for NextCloud, ensuring proper URL handling and security directives.

Create a dedicated virtual host configuration file:

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

Add the following comprehensive virtual host configuration:

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /var/www/html/nextcloud
    
    <Directory /var/www/html/nextcloud>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
        
        <IfModule mod_dav.c>
            Dav off
        </IfModule>
        
        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
    </Directory>
    
    ErrorLog /var/log/httpd/nextcloud_error.log
    CustomLog /var/log/httpd/nextcloud_access.log combined
</VirtualHost>

If you plan to use SSL (highly recommended), create an HTTPS virtual host:

<VirtualHost *:443>
    ServerName your-domain.com
    DocumentRoot /var/www/html/nextcloud
    
    SSLEngine on
    SSLCertificateFile /path/to/your/certificate.crt
    SSLCertificateKeyFile /path/to/your/private.key
    
    <Directory /var/www/html/nextcloud>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
        
        <IfModule mod_dav.c>
            Dav off
        </IfModule>
        
        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
    </Directory>
    
    ErrorLog /var/log/httpd/nextcloud_ssl_error.log
    CustomLog /var/log/httpd/nextcloud_ssl_access.log combined
</VirtualHost>

Test the Apache configuration for syntax errors:

sudo httpd -t

If the configuration test passes, restart Apache:

sudo systemctl restart httpd

Verify the virtual host is active:

sudo httpd -S

This command displays all configured virtual hosts and their status.

Web-Based Installation Setup

NextCloud’s web-based installer provides an intuitive interface for completing the installation process. This section guides you through the final configuration steps.

Open your web browser and navigate to your NextCloud installation:

http://your-server-ip/nextcloud

The NextCloud setup wizard will appear, prompting for initial configuration.

Install NextCloud on AlmaLinux 10

Create administrator account: Enter a secure username and password for the administrative account. This account will have full access to manage your NextCloud instance.

Configure data folder: The installer suggests using the default data directory within the NextCloud installation. For enhanced security, specify the external data directory created earlier:

/var/www/nextcloud-data

Database configuration: Select “MySQL/MariaDB” as the database type and enter the connection details:

  • Database user: nextcloud_user
  • Database password: your_secure_password
  • Database name: nextcloud_db
  • Database host: localhost

Performance and security settings: The installer may display warnings about PHP configuration or missing recommended modules. Address these by:

  • Ensuring all required PHP modules are installed
  • Configuring PHP memory limits as specified earlier
  • Setting up proper caching mechanisms

Click “Finish setup” to complete the installation process. NextCloud will create the necessary database tables and configure the application.

First login: After installation completes, you’ll be redirected to the NextCloud dashboard. Log in using the administrator credentials you created.

Initial configuration verification: Test basic functionality by:

  • Uploading a test file
  • Creating a user folder
  • Accessing the administrative settings panel
  • Verifying database connectivity through the status overview

The installation process typically takes 2-5 minutes depending on server performance and network connectivity.

Post-Installation Security and Optimization

Securing and optimizing your NextCloud installation ensures reliable performance and protects against potential security threats.

SSL/TLS certificate installation is crucial for production deployments. Install Let’s Encrypt certificates using Certbot:

sudo dnf install -y certbot python3-certbot-apache
sudo certbot --apache -d your-domain.com

Configure automatic certificate renewal:

sudo systemctl enable --now certbot-renew.timer

Performance optimization involves several configuration adjustments. Install Redis for memory caching:

sudo dnf install -y redis
sudo systemctl start redis
sudo systemctl enable redis

Configure NextCloud to use Redis by editing the configuration file:

sudo nano /var/www/html/nextcloud/config/config.php

Add Redis configuration:

'memcache.local' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => array(
    'host' => 'localhost',
    'port' => 6379,
),

Security hardening includes implementing additional protective measures:

Configure proper file permissions recursively:

sudo find /var/www/html/nextcloud/ -type f -print0 | xargs -0 chmod 0644
sudo find /var/www/html/nextcloud/ -type d -print0 | xargs -0 chmod 0755

Enable two-factor authentication through NextCloud’s app store for enhanced account security.

Backup strategy implementation ensures data protection:

Create automated database backup scripts:

#!/bin/bash
mysqldump -u nextcloud_user -p'your_password' nextcloud_db > /backup/nextcloud-db-$(date +%Y%m%d).sql

Configure regular file system backups using rsync or your preferred backup solution.

Common Troubleshooting Issues

NextCloud installations may encounter various issues that require systematic troubleshooting approaches.

Installation problems often stem from missing dependencies or configuration errors:

  • PHP module errors: Verify all required modules are installed using php -m
  • Database connection failures: Check credentials and MariaDB service status
  • Permission issues: Ensure Apache has proper read/write access to NextCloud directories

Performance problems typically indicate resource constraints or misconfiguration:

  • Slow loading times: Check PHP memory limits and enable OPcache
  • Database bottlenecks: Optimize MariaDB configuration and consider indexing
  • File upload failures: Verify PHP upload limits match your requirements

SELinux-related issues require careful analysis of audit logs:

sudo ausearch -m avc -ts recent | grep nextcloud

Use sealert to analyze denials and generate appropriate policies.

SSL certificate problems often involve incorrect configuration or expired certificates:

  • Verify certificate validity using openssl x509 -in certificate.crt -text -noout
  • Check Apache SSL configuration syntax
  • Ensure firewall allows HTTPS traffic

Log file analysis provides valuable troubleshooting information:

sudo tail -f /var/log/httpd/nextcloud_error.log
sudo tail -f /var/www/html/nextcloud/data/nextcloud.log

Monitor these logs during problematic operations to identify root causes.

Maintenance and Updates

Regular maintenance ensures your NextCloud installation remains secure, performant, and up-to-date with the latest features and security patches.

Update procedures should follow a systematic approach:

Before updating, create complete backups of both database and files. Use NextCloud’s built-in updater through the web interface or command line:

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

Database maintenance involves regular optimization tasks:

sudo -u apache php /var/www/html/nextcloud/occ db:add-missing-indices
sudo -u apache php /var/www/html/nextcloud/occ db:convert-filecache-bigint

Log management prevents disk space issues:

Configure log rotation in NextCloud settings or implement system-level log rotation for web server logs.

User account management includes monitoring active users and managing storage quotas through the administrative interface.

App management involves keeping installed applications updated and removing unused extensions to minimize security risks.

Performance monitoring should include regular checks of system resources, database performance, and user experience metrics.

Congratulations! You have successfully installed NextCloud. Thanks for using this tutorial for installing NextCloud open-source self-hosted on your AlmaLinux OS 10 system. For additional help 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