Find a file
2025-11-23 11:29:02 +00:00
.env Add Nextcloud docker-compose configuration 2025-11-23 09:57:14 +00:00
docker-compose.yml Add Nextcloud docker-compose configuration 2025-11-23 09:57:14 +00:00
install.sh added instalation script 2025-11-23 10:06:37 +00:00
readme.md added readme filče 2025-11-23 11:29:02 +00:00
remove-data.sh Add Nextcloud docker-compose configuration 2025-11-23 09:57:14 +00:00

Nextcloud Docker Installation

This repository contains a complete Docker Compose setup for Nextcloud with Traefik reverse proxy and optional NAS storage integration.

📋 Prerequisites

  • Ubuntu/Debian server with Docker and Docker Compose installed
  • Traefik reverse proxy running with Let's Encrypt
  • (Optional) NAS storage accessible via SMB/CIFS or NFS
  • Domain name pointing to your server

🚀 Quick Installation

Run the installation script which will guide you through the setup:

chmod +x install.sh
sudo ./install.sh

The script will:

  • Prompt for domain, admin credentials, and NAS settings
  • Install required packages
  • Mount NAS storage (if selected)
  • Create docker-compose.yml and .env files
  • Set proper permissions
  • Start Nextcloud

Option 2: Manual Installation

1. Clone or Download This Repository

git clone https://forgejo.rozic-dev.com/rozic-dev-server/Nexcloud.git
cd Nexcloud

2. Configure Environment Variables

Create a .env file:

cp .env.example .env
nano .env

Edit the values:

ADMIN_USERNAME=admin
ADMIN_PASSWORD=your_secure_password_here
NEXTCLOUD_DOMAIN=nextcloud.rozic-dev.com

3. Mount NAS Storage (Optional)

If you want to store Nextcloud data on a NAS:

Install Required Packages
sudo apt update
sudo apt install cifs-utils nfs-common
Create Mount Point
sudo mkdir -p /mnt/nextcloud
Mount NAS Share

For SMB/CIFS (Synology, QNAP, Windows shares):

sudo mount -t cifs //NAS_IP/ShareName /mnt/nextcloud \
  -o username=YOUR_USER,password=YOUR_PASS,vers=3.0,uid=33,gid=33,file_mode=0770,dir_mode=0770,noperm,iocharset=utf8

For NFS:

sudo mount -t nfs NAS_IP:/volume1/nextcloud /mnt/nextcloud
Make Mount Persistent (Auto-mount on Boot)

Edit /etc/fstab:

sudo nano /etc/fstab

Add this line at the end:

For SMB/CIFS:

# Nextcloud NAS storage
//192.168.107.90/Data/backup/Nextcloud /mnt/nextcloud cifs username=YOUR_USER,password=YOUR_PASS,vers=3.0,uid=33,gid=33,file_mode=0770,dir_mode=0770,noperm,iocharset=utf8,_netdev,nofail 0 0

For NFS:

# Nextcloud NAS storage  
NAS_IP:/volume1/nextcloud /mnt/nextcloud nfs defaults,_netdev,nofail 0 0
Test fstab Entry
sudo umount /mnt/nextcloud
sudo mount -a
df -h | grep nextcloud
Set Permissions
sudo chown -R 33:33 /mnt/nextcloud
sudo chmod -R 750 /mnt/nextcloud

Note: UID/GID 33 is the www-data user inside the Nextcloud container.

4. Update docker-compose.yml

If using NAS storage, ensure the volume mount points to your NAS mount:

volumes:
  - nextcloud:/var/www/html
  - /mnt/nextcloud:/var/www/html/data  # NAS storage

If using local storage:

volumes:
  - nextcloud:/var/www/html
  - /mnt/nextcloud/data:/var/www/html/data  # Local storage

5. Start Nextcloud

docker-compose up -d

6. Monitor Installation

docker-compose logs -f nextcloud

Wait until you see "Nextcloud was successfully installed"

🌐 Access Nextcloud

Open your browser and navigate to:

https://nextcloud.rozic-dev.com

Login with the credentials from your .env file.

🔧 Post-Installation Configuration

Add a cron job for better performance:

# Edit root crontab
sudo crontab -e

# Add this line (runs every 5 minutes)
*/5 * * * * docker exec -u www-data nextcloud_server php cron.php

Then in Nextcloud:

  1. Go to SettingsAdministrationBasic settings
  2. Change background jobs from "AJAX" to "Cron"

2. Configure Email (Optional)

In Nextcloud admin settings, configure SMTP for password resets and notifications.

Go to Apps and install:

  • Calendar
  • Contacts
  • Tasks
  • Talk (for video calls)
  • Deck (Kanban board)

4. Configure External Storage (Alternative to NAS mount)

If you prefer to use Nextcloud's external storage feature instead of direct NAS mounting:

  1. Enable the "External storage support" app
  2. Go to SettingsAdministrationExternal storage
  3. Add your NAS as SMB/CIFS or NFS storage

📊 Management Commands

View Logs

docker-compose logs -f nextcloud
docker-compose logs -f mariadb
docker-compose logs -f redis

Restart Services

docker-compose restart

Stop Services

docker-compose down

Update Nextcloud

docker-compose pull
docker-compose up -d

Backup Database

docker exec nextcloud_mariadb mysqldump -u nextcloud -pnextcloud nextcloud > nextcloud_backup_$(date +%Y%m%d).sql

Access Nextcloud CLI (occ)

docker exec -u www-data nextcloud_server php occ [command]

Examples:

# Check status
docker exec -u www-data nextcloud_server php occ status

# List users
docker exec -u www-data nextcloud_server php occ user:list

# Run maintenance mode
docker exec -u www-data nextcloud_server php occ maintenance:mode --on

🗂️ File Structure

Nextcloud/
├── docker-compose.yml    # Main Docker Compose configuration
├── .env                  # Environment variables (credentials, domain)
├── install.sh           # Automated installation script
├── remove-data.sh       # Script to clean installation
└── README.md            # This file

🔒 Security Notes

  1. Change default passwords in production (database, Redis, admin)
  2. Enable 2FA for admin account
  3. Regular backups of database and data directory
  4. Keep Docker images updated regularly
  5. Use strong passwords for NAS and Nextcloud admin
  6. Restrict file permissions on .env file:
    chmod 600 .env
    

🐛 Troubleshooting

NAS Mount Issues

Check if mounted:

df -h | grep nextcloud
mount | grep nextcloud

Test NAS connection:

ping NAS_IP
smbclient -L //NAS_IP -U username

Remount manually:

sudo umount /mnt/nextcloud
sudo mount -a

Check mount logs:

dmesg | grep -i cifs
journalctl -xe | grep mount

Permission Issues

If you get permission errors:

# Fix data directory permissions
sudo chown -R 33:33 /mnt/nextcloud
sudo chmod -R 750 /mnt/nextcloud

# Restart Nextcloud
docker-compose restart nextcloud

Database Connection Issues

# Check if MariaDB is running
docker-compose ps mariadb

# View MariaDB logs
docker-compose logs mariadb

# Test database connection
docker exec -it nextcloud_mariadb mysql -u nextcloud -pnextcloud nextcloud

Redis Connection Issues

# Check Redis
docker-compose ps redis

# Test Redis connection
docker exec -it nextcloud_redis redis-cli -a nextcloud ping

Nextcloud Shows "Access through untrusted domain"

Add your domain to trusted domains:

docker exec -u www-data nextcloud_server php occ config:system:set trusted_domains 1 --value=your-domain.com

Clear Installation and Start Fresh

# Stop containers
docker-compose down

# Remove volumes (WARNING: This deletes all data!)
docker volume rm nextcloud_mysql nextcloud_redis nextcloud_nextcloud

# Clear data directory
sudo rm -rf /mnt/nextcloud/data/*

# Start again
docker-compose up -d

Or use the cleanup script:

chmod +x remove-data.sh
sudo ./remove-data.sh

📚 Additional Resources

📝 Notes

  • Data Location: All user files are stored in /mnt/nextcloud (or your configured NAS path)
  • Database: MariaDB 10.11 with optimized settings for Nextcloud
  • Redis: Used for session handling and caching
  • Traefik: Handles SSL certificates via Let's Encrypt automatically
  • Backups: Remember to backup both database and data directory regularly

💡 Tips

  1. Performance: Use Redis for memory caching to improve performance
  2. Storage: Monitor disk space regularly, especially if storing large files
  3. Updates: Always backup before updating Nextcloud
  4. Apps: Only install apps you actually need to keep system lean
  5. Monitoring: Set up monitoring for disk space and service health

🤝 Support

For issues or questions:

📄 License

This configuration is provided as-is for personal and commercial use.