# Nextcloud Installation Guide
**Complete Setup with MariaDB, PHP 8.3 FPM, Apache HTTP/2, and Redis**
## Difficulty Level
**Intermediate to Advanced** – This guide requires familiarity with Linux command line, web server configuration, and database management. Estimated completion time: 2-3 hours.
## Prerequisites
– Ubuntu 22.04 LTS or Debian 11/12 server
– Root or sudo access
– Basic knowledge of Linux commands
– Understanding of web server concepts
– Familiarity with database operations
## System Requirements
– Minimum 2GB RAM (4GB recommended)
– 20GB+ available disk space
– Network access for package downloads
– Domain name configured (optional but recommended)
—
## Step 1: System Preparation
### Update System Packages
“`bash
sudo apt update && sudo apt upgrade -y
sudo apt install curl wget gnupg2 software-properties-common apt-transport-https -y
“`
### Install Required System Packages
“`bash
sudo apt install unzip zip p7zip-full htop tree -y
“`
—
## Step 2: Install and Configure Apache
### Install Apache
“`bash
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2
“`
### Enable Required Apache Modules
“`bash
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod env
sudo a2enmod dir
sudo a2enmod mime
sudo a2enmod ssl
sudo a2enmod http2
sudo a2enmod proxy_fcgi
sudo a2enmod setenvif
“`
### Configure Apache for HTTP/2
Create or edit the main Apache configuration:
“`bash
sudo nano /etc/apache2/conf-available/http2.conf
“`
Add the following content:
“`apache
# Enable HTTP/2
Protocols h2 h2c http/1.1
# HTTP/2 specific settings
H2Direct on
H2Push on
H2PushPriority * after
H2PushPriority text/css before
H2PushPriority image/png after 32
H2PushPriority application/javascript interleaved
“`
Enable the configuration:
“`bash
sudo a2enconf http2
sudo systemctl restart apache2
“`
—
## Step 3: Install PHP 8.3 with FPM
### Add PHP Repository
“`bash
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
“`
### Install PHP 8.3 and Required Extensions
“`bash
sudo apt install php8.3-fpm php8.3-common php8.3-mysql php8.3-xml php8.3-xmlrpc \
php8.3-curl php8.3-gd php8.3-imagick php8.3-cli php8.3-dev php8.3-imap \
php8.3-mbstring php8.3-opcache php8.3-redis php8.3-soap php8.3-zip \
php8.3-intl php8.3-bcmath php8.3-gmp php8.3-apcu php8.3-memcached -y
“`
### Configure PHP-FPM
Edit the PHP-FPM pool configuration:
“`bash
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
“`
Find and modify these settings:
“`ini
user = www-data
group = www-data
listen = /run/php/php8.3-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
“`
### Configure PHP Settings
Edit PHP configuration for better Nextcloud performance:
“`bash
sudo nano /etc/php/8.3/fpm/php.ini
“`
Modify these values:
“`ini
memory_limit = 512M
upload_max_filesize = 1G
post_max_size = 1G
max_execution_time = 300
max_input_time = 300
max_input_vars = 10000
date.timezone = “Europe/Berlin”
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
“`bash
sudo systemctl enable php8.3-fpm
sudo systemctl start php8.3-fpm
sudo systemctl restart apache2
“`
—
## Step 4: Install and Configure MariaDB
### Install MariaDB
“`bash
sudo apt install mariadb-server mariadb-client -y
sudo systemctl enable mariadb
sudo systemctl start mariadb
“`
### Secure MariaDB Installation
“`bash
sudo mysql_secure_installation
“`
Follow the prompts:
– Set root password: **YES**
– Remove anonymous users: **YES**
– Disallow root login remotely: **YES**
– Remove test database: **YES**
– Reload privilege tables: **YES**
### Create Nextcloud Database
“`bash
sudo mysql -u root -p
“`
Execute these SQL commands:
“`sql
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER ‘nextclouduser’@’localhost’ IDENTIFIED BY ‘your_strong_password_here’;
GRANT ALL PRIVILEGES ON nextcloud.* TO ‘nextclouduser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;
“`
### Optimize MariaDB for Nextcloud
“`bash
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
“`
Add under `[mysqld]` section:
“`ini
innodb_buffer_pool_size = 1G
innodb_io_capacity = 4000
skip-name-resolve
innodb_flush_method = O_DIRECT
innodb_log_file_size = 128M
innodb_flush_log_at_trx_commit = 2
“`
Restart MariaDB:
“`bash
sudo systemctl restart mariadb
“`
—
## Step 5: Install and Configure Redis
### Install Redis
“`bash
sudo apt install redis-server -y
sudo systemctl enable redis-server
sudo systemctl start redis-server
“`
### Configure Redis
“`bash
sudo nano /etc/redis/redis.conf
“`
Modify these settings:
“`ini
# Memory optimization
maxmemory 256mb
maxmemory-policy allkeys-lru
# Security
requirepass your_redis_password_here
# Network
bind 127.0.0.1 ::1
port 6379
“`
Restart Redis:
“`bash
sudo systemctl restart redis-server
“`
—
## Step 6: Download and Install Nextcloud
### Download Latest Nextcloud
“`bash
cd /tmp
wget https://download.nextcloud.com/server/releases/latest.zip
“`
### Extract and Move to Web Directory
“`bash
sudo unzip latest.zip -d /var/www/
sudo chown -R www-data:www-data /var/www/nextcloud
sudo chmod -R 755 /var/www/nextcloud
“`
—
## Step 7: Configure Apache Virtual Host
### Create Nextcloud Virtual Host
“`bash
sudo nano /etc/apache2/sites-available/nextcloud.conf
“`
Add the following configuration:
“`apache
<VirtualHost *:80>
ServerName your-domain.com
DocumentRoot /var/www/nextcloud
<Directory /var/www/nextcloud>
Options +FollowSymlinks
AllowOverride All
Require all granted
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
</Directory>
# PHP-FPM Configuration
<FilesMatch \.php$>
SetHandler “proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost/”
</FilesMatch>
# Security Headers
Header always set Strict-Transport-Security “max-age=63072000; includeSubDomains; preload”
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection “1; mode=block”
Header always set Referrer-Policy “no-referrer”
ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>
“`
### Enable Site and Restart Apache
“`bash
sudo a2ensite nextcloud.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2
“`
—
## Step 8: Complete Nextcloud Installation
### Set Proper Permissions
“`bash
sudo chown -R www-data:www-data /var/www/nextcloud
sudo find /var/www/nextcloud -type d -exec chmod 750 {} \;
sudo find /var/www/nextcloud -type f -exec chmod 640 {} \;
“`
### Web-based Installation
1. Open your browser and navigate to `http://your-domain.com`
2. Create an admin account
3. Configure database connection:
– Database user: `nextclouduser`
– Database password: `your_strong_password_here`
– Database name: `nextcloud`
– Database host: `localhost`
—
## Step 9: Post-Installation Configuration
### Configure Nextcloud for Redis
“`bash
sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.local –value=”\\OC\\Memcache\\APCu”
sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.distributed –value=”\\OC\\Memcache\\Redis”
sudo -u www-data php /var/www/nextcloud/occ config:system:set memcache.locking –value=”\\OC\\Memcache\\Redis”
sudo -u www-data php /var/www/nextcloud/occ config:system:set redis host –value=”localhost”
sudo -u www-data php /var/www/nextcloud/occ config:system:set redis port –value=6379
sudo -u www-data php /var/www/nextcloud/occ config:system:set redis password –value=”your_redis_password_here”
“`
### Configure Trusted Domains
“`bash
sudo -u www-data php /var/www/nextcloud/occ config:system:set trusted_domains 0 –value=”your-domain.com”
“`
### Setup Cron Job
“`bash
sudo crontab -u www-data -e
“`
Add this line:
“`bash
*/5 * * * * php /var/www/nextcloud/cron.php
“`
—
## Step 10: SSL/TLS Configuration (Recommended)
### Install Certbot
“`bash
sudo apt install certbot python3-certbot-apache -y
“`
### Obtain SSL Certificate
“`bash
sudo certbot –apache -d your-domain.com
“`
### Update Virtual Host for SSL
The SSL configuration will be automatically created. Verify HTTP/2 is working:
“`bash
curl -I -L https://your-domain.com
“`
—
## Step 11: Performance Optimization
### Configure PHP OPcache
“`bash
sudo nano /etc/php/8.3/fpm/conf.d/10-opcache.ini
“`
Add optimized settings:
“`ini
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1
“`
### Restart Services
“`bash
sudo systemctl restart php8.3-fpm
sudo systemctl restart apache2
“`
—
## Verification and Testing
### Check Service Status
“`bash
sudo systemctl status apache2
sudo systemctl status php8.3-fpm
sudo systemctl status mariadb
sudo systemctl status redis-server
“`
### Test HTTP/2 Support
“`bash
curl -I -L https://your-domain.com | grep -i http
“`
### Verify Nextcloud Status
“`bash
sudo -u www-data php /var/www/nextcloud/occ status
“`
—
## Troubleshooting
### Common Issues and Solutions
**Permission Problems:**
“`bash
sudo chown -R www-data:www-data /var/www/nextcloud
sudo chmod -R 755 /var/www/nextcloud
“`
**PHP-FPM Socket Issues:**
“`bash
sudo systemctl restart php8.3-fpm
sudo systemctl restart apache2
“`
**Database Connection Problems:**
– Verify MariaDB is running
– Check database credentials
– Ensure user has proper privileges
**Redis Connection Issues:**
“`bash
redis-cli ping
redis-cli -a your_redis_password_here ping
“`
—
## Security Recommendations
1. **Regular Updates:** Keep all components updated
2. **Firewall:** Configure UFW or iptables
3. **Backup Strategy:** Implement regular database and file backups
4. **Monitor Logs:** Regularly check Apache and Nextcloud logs
5. **Two-Factor Authentication:** Enable 2FA for admin accounts
—
## Maintenance Commands
### Update Nextcloud
“`bash
sudo -u www-data php /var/www/nextcloud/updater/updater.phar
“`
### Database Maintenance
“`bash
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices
sudo -u www-data php /var/www/nextcloud/occ db:convert-filecache-bigint
“`
### Clear Cache
“`bash
sudo -u www-data php /var/www/nextcloud/occ maintenance:repair –include-expensive
“`
—
## Conclusion
Your Nextcloud installation is now complete with:
– PHP 8.3 FPM for optimal performance
– MariaDB for reliable data storage
– Redis for enhanced caching
– Apache with HTTP/2 support
– SSL/TLS encryption
– Performance optimizations
Access your Nextcloud instance at `https://your-domain.com` and begin configuring your cloud storage solution.