2025-11-23 11:29:02 +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
|
|
|
|
|
|
|
|
|
|
### Option 1: Automated Installation (Recommended)
|
|
|
|
|
|
|
|
|
|
Run the installation script which will guide you through the setup:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
git clone https://forgejo.rozic-dev.com/rozic-dev-server/Nexcloud.git
|
|
|
|
|
cd Nexcloud
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2. Configure Environment Variables
|
|
|
|
|
|
|
|
|
|
Create a `.env` file:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cp .env.example .env
|
|
|
|
|
nano .env
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Edit the values:
|
|
|
|
|
|
|
|
|
|
```env
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo apt update
|
|
|
|
|
sudo apt install cifs-utils nfs-common
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### Create Mount Point
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo mkdir -p /mnt/nextcloud
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### Mount NAS Share
|
|
|
|
|
|
|
|
|
|
**For SMB/CIFS (Synology, QNAP, Windows shares):**
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
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:**
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo mount -t nfs NAS_IP:/volume1/nextcloud /mnt/nextcloud
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### Make Mount Persistent (Auto-mount on Boot)
|
|
|
|
|
|
|
|
|
|
Edit `/etc/fstab`:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo umount /mnt/nextcloud
|
|
|
|
|
sudo mount -a
|
|
|
|
|
df -h | grep nextcloud
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### Set Permissions
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
volumes:
|
|
|
|
|
- nextcloud:/var/www/html
|
|
|
|
|
- /mnt/nextcloud:/var/www/html/data # NAS storage
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
If using local storage:
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
volumes:
|
|
|
|
|
- nextcloud:/var/www/html
|
|
|
|
|
- /mnt/nextcloud/data:/var/www/html/data # Local storage
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 5. Start Nextcloud
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker-compose up -d
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 6. Monitor Installation
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
### 1. Configure Background Jobs (Recommended)
|
|
|
|
|
|
|
|
|
|
Add a cron job for better performance:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 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 **Settings** → **Administration** → **Basic settings**
|
|
|
|
|
2. Change background jobs from "AJAX" to "Cron"
|
|
|
|
|
|
|
|
|
|
### 2. Configure Email (Optional)
|
|
|
|
|
|
|
|
|
|
In Nextcloud admin settings, configure SMTP for password resets and notifications.
|
|
|
|
|
|
|
|
|
|
### 3. Install Recommended Apps
|
|
|
|
|
|
|
|
|
|
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 **Settings** → **Administration** → **External storage**
|
|
|
|
|
3. Add your NAS as SMB/CIFS or NFS storage
|
|
|
|
|
|
|
|
|
|
## 📊 Management Commands
|
|
|
|
|
|
|
|
|
|
### View Logs
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker-compose logs -f nextcloud
|
|
|
|
|
docker-compose logs -f mariadb
|
|
|
|
|
docker-compose logs -f redis
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Restart Services
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker-compose restart
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Stop Services
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker-compose down
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Update Nextcloud
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker-compose pull
|
|
|
|
|
docker-compose up -d
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Backup Database
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker exec nextcloud_mariadb mysqldump -u nextcloud -pnextcloud nextcloud > nextcloud_backup_$(date +%Y%m%d).sql
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Access Nextcloud CLI (occ)
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker exec -u www-data nextcloud_server php occ [command]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
```bash
|
|
|
|
|
# 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:
|
|
|
|
|
```bash
|
|
|
|
|
chmod 600 .env
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 🐛 Troubleshooting
|
|
|
|
|
|
|
|
|
|
### NAS Mount Issues
|
|
|
|
|
|
|
|
|
|
**Check if mounted:**
|
|
|
|
|
```bash
|
|
|
|
|
df -h | grep nextcloud
|
|
|
|
|
mount | grep nextcloud
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Test NAS connection:**
|
|
|
|
|
```bash
|
|
|
|
|
ping NAS_IP
|
|
|
|
|
smbclient -L //NAS_IP -U username
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Remount manually:**
|
|
|
|
|
```bash
|
|
|
|
|
sudo umount /mnt/nextcloud
|
|
|
|
|
sudo mount -a
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Check mount logs:**
|
|
|
|
|
```bash
|
|
|
|
|
dmesg | grep -i cifs
|
|
|
|
|
journalctl -xe | grep mount
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Permission Issues
|
|
|
|
|
|
|
|
|
|
If you get permission errors:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 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:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker exec -u www-data nextcloud_server php occ config:system:set trusted_domains 1 --value=your-domain.com
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Clear Installation and Start Fresh
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 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:
|
|
|
|
|
```bash
|
|
|
|
|
chmod +x remove-data.sh
|
|
|
|
|
sudo ./remove-data.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 📚 Additional Resources
|
|
|
|
|
|
|
|
|
|
- [Nextcloud Documentation](https://docs.nextcloud.com/)
|
|
|
|
|
- [Nextcloud Admin Manual](https://docs.nextcloud.com/server/latest/admin_manual/)
|
|
|
|
|
- [Docker Hub - Nextcloud](https://hub.docker.com/_/nextcloud)
|
|
|
|
|
- [Traefik Documentation](https://doc.traefik.io/traefik/)
|
|
|
|
|
|
|
|
|
|
## 📝 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:
|
|
|
|
|
- Check the Nextcloud logs: `docker-compose logs -f nextcloud`
|
|
|
|
|
- Visit [Nextcloud Community Forum](https://help.nextcloud.com/)
|
|
|
|
|
- Check [Nextcloud GitHub Issues](https://github.com/nextcloud/server/issues)
|
|
|
|
|
|
|
|
|
|
## 📄 License
|
|
|
|
|
|
|
|
|
|
This configuration is provided as-is for personal and commercial use.
|