TechBuzzPro

Install Nextcloud on CentOS: Step-by-Step Guide

· 5 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through installing and configuring Nextcloud on CentOS (7, 8, or 9). By the end, you'll have a self-hosted file sync and sharing server accessible via HTTPS, with a database backend and proper file permissions. You'll need a CentOS server with root or sudo access, a domain name or IP address, and a basic comfort with the command line.

What You'll Need

  • A CentOS server (7, 8, or 9) with at least 2 GB RAM and 20 GB free disk space
  • Root or sudo access to the server
  • A domain name pointing to your server's IP (optional but recommended for SSL)
  • Open ports 80 and 443 in your firewall

Step-by-Step

  1. Update the system
    Log in via SSH and run:
    sudo yum update -y   # CentOS 7/8
    sudo dnf update -y   # CentOS 9
    Reboot if the kernel was updated.
  2. Install the Remi repository (for PHP 8.1+)
    Nextcloud 27+ requires PHP 8.1. CentOS's default PHP is too old. Install Remi:
    sudo yum install -y epel-release
    sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm   # CentOS 7
    sudo dnf install -y epel-release
    sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm   # CentOS 8
    sudo dnf install -y epel-release
    sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm   # CentOS 9
    Then enable PHP 8.1:
    sudo yum module reset php -y   # CentOS 8/9
    sudo yum module enable php:remi-8.1 -y
  3. Install required packages
    Install Apache, PHP, and necessary extensions:
    sudo yum install -y httpd php php-gd php-mbstring php-intl php-mysqlnd php-xml php-json php-zip php-curl php-bz2 php-imagick php-gmp php-bcmath php-apcu
    For MariaDB (database) also install:
    sudo yum install -y mariadb-server
  4. Start and enable services
    sudo systemctl start httpd mariadb
    sudo systemctl enable httpd mariadb
  5. Secure MariaDB
    sudo mysql_secure_installation
    Set a root password, remove anonymous users, disable remote root login, and remove test databases.
  6. Create the Nextcloud database and user
    sudo mysql -u root -p
    Then run:
    CREATE DATABASE nextcloud;
    CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'strong-password';
    GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  7. Download Nextcloud
    Get the latest version from nextcloud.com/install. Replace the version number with the current one:
    cd /var/www/html
    sudo wget https://download.nextcloud.com/server/releases/nextcloud-28.0.1.zip
    If wget is missing, install it: sudo yum install -y wget unzip
  8. Extract and set permissions
    sudo unzip nextcloud-28.0.1.zip
    sudo chown -R apache:apache nextcloud
    sudo chmod -R 755 nextcloud
  9. Configure Apache virtual host
    Create /etc/httpd/conf.d/nextcloud.conf with:
    <VirtualHost *:80>
        DocumentRoot /var/www/html/nextcloud
        ServerName your-domain.com
        <Directory /var/www/html/nextcloud>
            Require all granted
            Options FollowSymlinks
            AllowOverride All
            <IfModule mod_dav.c>
                Dav off
            </IfModule>
        </Directory>
    </VirtualHost>
    Then restart Apache: sudo systemctl restart httpd
  10. Set up SSL (HTTPS)
    Use Let's Encrypt with certbot:
    sudo yum install -y certbot python2-certbot-apache   # CentOS 7
    sudo dnf install -y certbot python3-certbot-apache   # CentOS 8/9
    sudo certbot --apache -d your-domain.com
    Follow the prompts. Certbot will edit your Apache config and set up auto-renewal.
  11. Complete installation via web browser
    Navigate to https://your-domain.com. Create an admin account, enter the database details (nextcloud, nextclouduser, your password), and click "Finish setup".
  12. Configure trusted domains
    If you access via IP or a different domain, edit /var/www/html/nextcloud/config/config.php and add your domain to the trusted_domains array. Then restart Apache.

Common Mistakes

  • Forgetting to enable PHP extensions – Nextcloud will complain about missing modules. Double-check with php -m.
  • Wrong file permissions – If the web server can't write to the config or data directory, you'll see errors. Ensure chown -R apache:apache is run.
  • Using an outdated PHP version – CentOS's default PHP is 5.4 (CentOS 7) or 7.2 (CentOS 8). You must enable the Remi repo.
  • SELinux blocking access – SELinux often blocks Apache from writing to certain directories. Check with getenforce; if enforcing, either set it to permissive or apply the correct contexts.
  • Not setting a strong database password – Use a complex password and avoid reusing the admin password.

Tips

  • Use a dedicated data directory outside the web root (e.g., /var/ncdata) for better security and easier backups.
  • Set up a cron job for Nextcloud's background jobs instead of AJAX. Edit config.php and set 'backgroundjobs_mode' => 'cron', then add a cron entry: */5 * * * * php -f /var/www/html/nextcloud/cron.php.
  • Enable OPcache for better performance. Add to /etc/php.d/10-opcache.ini: opcache.enable=1, opcache.memory_consumption=128, opcache.max_accelerated_files=10000.
  • Regularly back up the config and data directories, and the database.
  • Use Redis for caching if you have many users. Install redis and php-pecl-redis, then add the config entries.

Troubleshooting

  • Web page shows "502 Bad Gateway" – Usually PHP-FPM isn't running. Check systemctl status php-fpm and start it.
  • Nextcloud says "Can't write into config directory" – Fix permissions: sudo chown -R apache:apache /var/www/html/nextcloud.
  • HTTPS certificate not renewing – Check certbot timer: sudo systemctl list-timers | grep certbot. If missing, add a cron job.
  • Database connection error – Verify MariaDB is running and the credentials are correct. Test with mysql -u nextclouduser -p.
  • Blank page after installation – Check Apache error logs: sudo tail -f /var/log/httpd/error_log. Often a missing PHP extension.
  • SELinux blocks access – Temporarily set to permissive with sudo setenforce 0 to test. If it works, add proper contexts: sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud(/.*)?' then restorecon -Rv /var/www/html/nextcloud.

Frequently Asked Questions

Can I install Nextcloud on CentOS 6?

No. CentOS 6 is end-of-life and doesn't meet Nextcloud's PHP and database requirements. Use CentOS 7 or newer.

What is the default data directory?

By default, Nextcloud stores data in /var/www/html/nextcloud/data. It's strongly recommended to move it outside the web root.

How do I update Nextcloud?

Use the built-in updater in the admin panel, or manually replace the files. Always back up before updating.

Can I use Nginx instead of Apache?

Yes, but the configuration differs. This guide focuses on Apache, which is the default on CentOS.

Why do I get a "Trusted domain" error?

You accessed Nextcloud via an IP or domain not listed in config.php. Add it to the trusted_domains array.

Is it safe to run Nextcloud on the default Apache port?

Yes, but you should use HTTPS (port 443) to encrypt traffic. The HTTP port can be redirected to HTTPS.