How to Install and Configure Nextcloud on CentOS Stream 9: Build Your Own Private Cloud

CentOS tutorial - IT technology blog
CentOS tutorial - IT technology blog

Internal File Storage: Which Solution Should Businesses Choose?

Consider a typical 30-person office. Every day, the accounting department shares reports over chat apps, HR sends contracts via personal Google Drive accounts, and the engineering team passes around a physical USB drive. When last year’s audit deadline arrived, download links had expired. An employee resigned and walked away with lingering access to the project document repository. Most critically, confidential contracts are constantly at risk of leaking.

To put an end to this chaos, IT professionals usually consider three approaches:

  • Subscribing to Public Cloud Services (Google Workspace, Dropbox, Microsoft 365): Ready to use out of the box with zero setup effort.
  • Purchasing a Network Attached Storage (NAS) Appliance (Synology, QNAP): Deploy a physical device right in the office and share directories across the local network (LAN).
  • Deploying an Open-Source Private Cloud (Nextcloud on Linux): Set up a cloud server on a VPS or on-premises server, retaining 100% ownership of your data.

Real-World Comparison: Costs and Trade-offs

Each solution comes with its own trade-offs. The right choice depends on your company’s budget and technical expertise.

1. Subscribing to Commercial Public Cloud

  • Pros: Virtually effortless. No dedicated IT operations needed, 99.9% uptime, and seamless built-in online document editing tools.
  • Cons: Costs escalate rapidly with scale. With a Google Workspace Business Standard plan ($12/user/month), a 30-person company will spend around $360 (approx. 9 million VND) per month, totaling over 100 million VND annually. Furthermore, storing all business data on third-party servers presents ongoing security and compliance concerns.

2. Investing in a Physical NAS Device

  • Pros: Impressive local transfer speeds, easily reaching 100–110 MB/s over a standard 1Gbps LAN port. User-friendly interface accessible even to non-technical users.
  • Cons: High upfront hardware costs. A 4-bay NAS appliance bundled with four 4TB drives can cost anywhere from 20 to 35 million VND ($800–$1,400). Moreover, for remote or hybrid employees, exposing ports to the internet carries significant vulnerability scanning and ransomware risks unless secured by a dedicated firewall or VPN.

3. Self-Hosting Nextcloud on CentOS Stream 9

  • Pros: Completely license-free. You can create 30 or 300 accounts without paying a dime in per-user fees. Desktop and mobile sync clients across Windows, macOS, Android, and iOS are stable and mature. All files remain securely hosted on your own infrastructure.
  • Cons: Requires fundamental Linux administration skills to set up the LAMP stack, configure firewalls, and troubleshoot issues when they arise.

Why Choose CentOS Stream 9 as Your Base?

CentOS Stream 9 delivers a modern Linux Kernel 5.14, updated package repositories, and inherits the enterprise-grade stability of the Red Hat Enterprise Linux (RHEL) ecosystem. It serves as an ideal foundation for deploying 24/7 production services without unexpected hiccups.

To comfortably serve an office of 30–50 people, you only need a server (or VPS) with minimum specs of 2–4 vCPUs, 4GB of RAM, and SSD/NVMe storage sized to your storage needs.

Step-by-Step Guide to Installing Nextcloud on CentOS Stream 9

The deployment process consists of 7 steps: installing the web server, configuring MariaDB, setting up PHP 8.2, downloading Nextcloud, creating an Apache VirtualHost, configuring SELinux permissions, and completing web-based setup.

Step 1: Install the Web Server and Database

Update the system to the latest packages, then install Apache and MariaDB:

sudo dnf update -y
sudo dnf install -y httpd mariadb-server mariadb

Enable and start both services so they run automatically on boot:

sudo systemctl enable --now httpd
sudo systemctl enable --now mariadb

Run the security script to set the root password and clean up test databases:

sudo mysql_secure_installation

Step 2: Install PHP 8.2 and Required Extensions

Nextcloud runs optimally on PHP 8.2. The default CentOS 9 repositories typically only include older PHP versions, so you need to enable the Remi repository:

sudo dnf install -y epel-release
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.2 -y

Next, install PHP 8.2 along with the required extensions. Make sure to include php-opcache and php-pecl-apcu to improve performance and response times:

sudo dnf install -y php php-cli php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-pdo php-opcache php-pecl-apcu php-pecl-imagick php-intl php-gmp

Step 3: Create a Database for Nextcloud

Log in to MariaDB as the root user:

sudo mysql -u root -p

Create a dedicated database and user, then grant access privileges. Be sure to replace the sample password with a strong password of your own:

CREATE DATABASE nextcloud_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nextcloud_user'@'localhost' IDENTIFIED BY 'VeryStrongPassword123@#';
GRANT ALL PRIVILEGES ON nextcloud_db.* TO 'nextcloud_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Bước 4: Download and Prepare Nextcloud Source Code

Download the latest Nextcloud release archive into the web root directory:

cd /var/www/html
sudo dnf install -y wget unzip
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo rm -f latest.zip

As a best security practice, the user data directory should reside outside the web root to eliminate the risk of direct file access via URLs. Create a separate /var/nextcloud_data directory:

sudo mkdir -p /var/nextcloud_data
sudo chown -R apache:apache /var/www/html/nextcloud
sudo chown -R apache:apache /var/nextcloud_data
sudo chmod -R 755 /var/www/html/nextcloud
sudo chmod -R 750 /var/nextcloud_data

Step 5: Configure Apache VirtualHost

Create a VirtualHost configuration file for the cloud instance:

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

Paste the following configuration into the file (replace cloud.yourdomain.com with your actual domain):

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/nextcloud/
    ServerName cloud.yourdomain.com

    <Directory /var/www/html/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
    </Directory>

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

Restart Apache to apply the new configuration:

sudo systemctl restart httpd

Step 6: Configure Firewall Ports and SELinux Contexts

Forgetting to configure the firewall or misconfiguring SELinux is the leading cause of blank pages or 403 Forbidden errors on RHEL and CentOS distributions.

First, open HTTP (port 80) and HTTPS (port 443) through the firewall:

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

Next, install the SELinux management tools if they are not already installed, then configure the appropriate contexts to allow Apache read/write access:

sudo dnf install -y policycoreutils-python-utils
sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/nextcloud_data(/.*)?'
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/config(/.*)?'
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/apps(/.*)?'
sudo restorecon -R -v /var/www/html/nextcloud
sudo restorecon -R -v /var/nextcloud_data

Step 7: Complete Setup via the Web Interface

Open your browser and navigate to http://SERVER_IP/nextcloud or the domain you pointed to your server:

  1. Create an administrator account (Admin username and password).
  2. Under Data folder, change the path to /var/nextcloud_data.
  3. Enter the MariaDB connection details created in Step 3: Database user (nextcloud_user), password, Database name (nextcloud_db), leaving the database host as localhost.
  4. Click Install and wait 1 to 2 minutes while the system initializes the database tables.

Once the main dashboard appears, your organization’s private cloud is ready for production. You can configure departmental folder permissions, deploy sync clients to employee workstations, and integrate a free SSL certificate from Let’s Encrypt to ensure all data in transit is encrypted.

Share: