Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save djalmaaraujo/592178b1f802d83a1b90161d5fbb2b76 to your computer and use it in GitHub Desktop.
Save djalmaaraujo/592178b1f802d83a1b90161d5fbb2b76 to your computer and use it in GitHub Desktop.
Install nextcloud on a macOS + Cloudflare tunnel (Macbook, mac mini) — 2025

🚀 Setting Up Nextcloud on macOS with Cloudflare Tunnel (No Port Forwarding)

This guide walks you through installing Nextcloud with Docker on macOS and exposing it publicly via Cloudflare Tunnel, ideal for dynamic IP setups where port forwarding is not possible. This setup ensures that Nextcloud runs automatically on reboot and is securely accessible over the internet.


🧩 Requirements

  • A macOS device (laptop, Mac mini, etc.)
  • Docker and Docker Compose installed
  • A registered domain in Cloudflare
  • Homebrew and cloudflared installed
  • Basic terminal usage knowledge

✅ Step 1 – Create a Cloudflare Account

  1. Go to https://cloudflare.com
  2. Create an account and add your domain (e.g., yourdomain.com)
  3. Point your DNS to Cloudflare's nameservers (Cloudflare will guide you)
  4. Once verified, go to DNS settings and create a record like:
Type: CNAME  
Name: nextcloud  
Target: `@` (or your main domain)  
Proxy status: Proxied (orange cloud)

✅ Step 2 – Log in with cloudflared and Create a Tunnel

Make sure cloudflared is installed:

brew install cloudflared

Then log in and authorize your domain:

cloudflared tunnel login

A browser window will open asking you to authenticate with Cloudflare.


✅ Step 3 – Install and Configure Nextcloud

Create a shell script with the full setup process:

nano ~/setup_nextcloud_tunnel.sh

Paste the script provided earlier (including tunnel ID fix). Save and run:

chmod +x ~/setup_nextcloud_tunnel.sh
./setup_nextcloud_tunnel.sh

The script will:

  • Create a Docker Compose file for Nextcloud
  • Spin up Nextcloud and MariaDB containers
  • Create a Cloudflare Tunnel and configure config.yml
  • Link the tunnel to your subdomain nextcloud.yourdomain.com
  • Launch the tunnel

✅ Step 4 – Finish Nextcloud Setup in the Browser

Open:

https://nextcloud.yourdomain.com

On the first load:

  • Set an admin username and password
  • Under Database, use:
    • Type: MySQL/MariaDB
    • User: nextcloud
    • Password: nextcloud
    • Database name: nextcloud
    • Host: db

Click Install.


✅ Step 5 – Enable Auto-Start on macOS Boot

5.1 Nextcloud via Docker Compose

Create a file ~/start_nextcloud.sh:

#!/bin/bash
export PATH="/opt/homebrew/bin:$PATH"
cd /Users/$(whoami)/nextcloud
docker-compose up -d

Make it executable:

chmod +x ~/start_nextcloud.sh

Create a launchd agent:

mkdir -p ~/Library/LaunchAgents
nano ~/Library/LaunchAgents/com.user.nextcloud.plist

Paste:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.user.nextcloud</string>

  <key>ProgramArguments</key>
  <array>
    <string>/Users/$(whoami)/start_nextcloud.sh</string>
  </array>

  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <false/>
</dict>
</plist>

Load the service:

launchctl load ~/Library/LaunchAgents/com.user.nextcloud.plist

5.2 Cloudflared Tunnel Auto-Start

Cloudflare has built-in support:

cloudflared service install

It will automatically run the tunnel on system boot using the config.yml.


✅ Done! 🎉

You now have:

  • A Nextcloud instance running on macOS
  • Publicly available at https://nextcloud.yourdomain.com
  • No open ports required
  • Automatically restarted after reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment