TODAY ONLY! TRY FOR FREE
08
:
00
:
00
Published Mar 11, 2025 ⦁ 7 min read
How to Set Up Self-Hosted Anki Sync Server

How to Set Up Self-Hosted Anki Sync Server

Want full control over your Anki flashcard sync? Setting up a self-hosted Anki sync server lets you manage your data, improve privacy, and enjoy faster sync speeds. Here’s what you’ll need and how to get started:

Why Self-Host?

  • Control Your Data: Store flashcards on your own server.
  • Better Privacy: Keep sensitive info off third-party services.
  • Faster Sync: No throttling or external server delays.
  • Reliability: Access your cards even if AnkiWeb is down.

What You’ll Need:

  • Tools: Python 3.9+, Git, and optionally Docker.
  • System: A machine with 2GB RAM, 1GB storage, and port 27701 open.
  • OS: Linux (Ubuntu/Debian), macOS, or Windows 10/11.

Quick Setup Steps:

  1. Choose Installation:
    • Docker (easier): Use a pre-built container.
    • Direct Install: Manually install dependencies.
  2. Run the Server:
    • Docker: Pull and run the container.
    • Direct: Clone the repo, install dependencies, and start the server.
  3. Configure Settings: Update config.json with your server details.
  4. Connect Devices: Update sync settings in Anki Desktop/Mobile.

Quick Comparison: Docker vs. Direct Install

Docker

Server Type Best For Resource Usage Setup Difficulty
Docker Container Production use Low–moderate Easy
Direct Install Development/testing Minimal Moderate

With your server running, you can sync flashcards across devices privately and reliably. Follow the article for detailed steps, troubleshooting tips, and maintenance advice.

Before You Start

Tools You'll Need

To set up your Anki sync server, you'll need to have the following tools ready:

Essential Tools

  • Python 3.9 or newer: Download it from python.org.
  • Git: Available at git-scm.com.
  • A terminal or command prompt for running commands.
  • Anki Desktop 2.1.50 or higher installed.

Optional Tools

  • Docker: Get it from docker.com.
  • A text editor like VS Code or Sublime Text for editing configuration files.
  • Network monitoring tools to help troubleshoot connectivity issues.

System Requirements

Your server needs to meet specific hardware and network conditions to run efficiently.

Hardware

  • Processor: A modern CPU (released in 2015 or later).
  • Memory: At least 2GB of free RAM.
  • Storage: 1GB for the server itself, plus additional space for your Anki cards.
  • Internet Speed: Recommended minimum of 10 Mbps.

Network Setup

  • Open port 27701 on your firewall.
  • Use a static IP address or set up Dynamic DNS (DDNS).
  • Ensure you can access the command line or terminal.

Supported Operating Systems

  • Linux: Ubuntu 20.04+ or Debian 11+.
  • macOS: Version 10.15 or newer.
  • Windows: Windows 10 or Windows 11.

For casual use at home, a desktop or laptop that meets these specs will work fine. However, if you plan to sync large collections (more than 10GB) or support multiple users, consider doubling the RAM and storage.

Important Note: Ensure your system clock is accurate and synchronized. This is critical for the server to function correctly. You'll also need administrator or root access to install and configure the server.

Once these requirements are in place, you're ready to begin setting up your Anki sync server.

Server Setup Steps

Pick Your Server Type

Decide which server type works best for your needs:

Server Type Best For Resource Usage Setup Difficulty
Docker Container Production environments Low–moderate Easy
Direct Installation Development/testing Minimal Moderate

Docker containers are ideal for their isolation and simple management, making them a great choice for production. On the other hand, direct installation is better suited for development or testing environments. Once you've chosen, proceed with the installation steps for your selected server type.

Install the Server

For Docker installation:

  1. Pull the Docker image:
    docker pull ankicommunity/anki-sync-server:latest
    
  2. Create a container:
    docker run -d --name anki-sync-server -p 27701:27701 -v /path/to/data:/data ankicommunity/anki-sync-server:latest
    

For direct installation:

  1. Clone the repository:
    git clone https://github.com/ankicommunity/anki-sync-server.git
    cd anki-sync-server
    
  2. Install the required dependencies:
    pip install -r requirements.txt
    
  3. Start the server:
    python -m anki_sync_server
    

After completing the installation, move on to configuring the server options.

Set Up Server Options

Create a config.json file in your data directory with the following content:

{
    "host": "0.0.0.0",
    "port": 27701,
    "data_root": "/path/to/data",
    "base_url": "http://your-server-address:27701/",
    "base_media_url": "http://your-server-address:27701/msync/",
    "auth_db_path": "/path/to/auth.db"
}
  • Set host to 0.0.0.0 to allow external access.
  • Use port 27701 unless a different port is required.
  • Update paths and URLs to match your server's environment.

To create your first user account, run:

python -m anki_sync_server --add-user username password

For security, always use strong passwords and enable SSL/TLS encryption if your server will be accessible online.

sbb-itb-1e479da

Connect Your Devices

Once your server is set up, it's time to connect your devices and start syncing.

Desktop Setup

To link Anki Desktop to your self-hosted sync server, follow these steps:

  1. Open Anki Desktop.
  2. Navigate to Tools > Preferences > Network.
  3. Check the option for Custom sync server.
  4. Enter your server information:
    • Sync URL: http://your-server-address:27701/
    • Media sync URL: http://your-server-address:27701/msync/
  5. Click OK to save the settings.
  6. Use Tools > Sync and log in with your username and password.

Note: Replace "your-server-address" with your actual server IP or domain. For local networks, use the server's IP (e.g., 192.168.1.100).

Mobile Setup

AnkiDroid (Android):

  1. Open AnkiDroid.
  2. Go to Settings > Advanced.
  3. Tap Custom Sync Server.
  4. Enter the following details:
    • Sync Server: http://your-server-address:27701/
    • Media Sync Server: http://your-server-address:27701/msync/
  5. Tap sync and provide your username and password.

AnkiMobile (iOS):

  1. Open AnkiMobile.
  2. Go to Settings > Synchronization.
  3. Enable the Custom Sync Server option.
  4. Enter the same server URLs as above.
  5. Save the settings and perform an initial sync.

Fix Connection Problems

If you encounter sync issues, here are some common problems and their solutions:

Problem Solution
Connection Timeout Ensure port 27701 is open in your firewall.
Authentication Failed Double-check your username and password.
SSL Certificate Error Verify your SSL configuration if using HTTPS.
Sync Conflict Decide whether to "Upload" or "Download" based on the correct data.

Additional Troubleshooting:

  • Test server connectivity using curl http://your-server-address:27701/.
  • Ensure your device is connected to the same network as the server.
  • Double-check for typos in your server URLs.
  • Confirm that your server's firewall allows incoming connections.
  • For remote access, verify your router's port forwarding settings.

If you're using SSL/TLS encryption, make sure all devices trust your certificate authority (CA). Self-signed certificates may require extra configuration, especially on mobile devices.

Server Management

Once your devices are connected, it's crucial to maintain your server through regular backups, updates, and security protocols. Proper server management ensures the stability and protection of your self-hosted Anki sync setup.

Backup Your Data

Regular backups are essential. Here are two key methods:

  • Database Backup: Automate backups for your SQLite database using a cron job:
    0 2 * * * sqlite3 /path/to/auth.db ".backup '/backup/auth-$(date +\%Y\%m\%d).db'"
    
    This script runs every day at 2 AM.
  • Collection Files Backup: Use rsync to back up your collections directory:
    0 3 * * * rsync -av /path/to/collections/ /backup/collections/
    
    Keep three recent backups in a secure, off-site location for added safety.

Update Your Server

When updating your server, follow these steps:

  1. Stop the server:
    systemctl stop anki-sync-server
    
  2. Back up your data.
  3. Update the software and test it on a staging environment.
  4. Restart the server:
    systemctl start anki-sync-server
    
    Tip: Always review the changelog before updating to ensure everything remains compatible with your setup.

Server Security

Protect your server by implementing these measures:

Measure How Why
SSL/TLS Use Let's Encrypt Encrypts data transmission
Firewall Rules Allow only ports 27701, 443 Reduces attack opportunities
Rate Limiting Set 100 requests/min/IP Stops brute force attempts
Access Logs Enable logging Tracks server activity

Additionally, use strong passwords, keep your operating system up to date, and regularly monitor resource usage.

Monitoring Commands:

  • Check server status:
    systemctl status anki-sync-server
    
  • Monitor logs in real-time:
    tail -f /var/log/anki-sync-server/access.log
    

Wrap-Up

Setup Summary

Creating your self-hosted Anki sync server requires several components working together to ensure smooth operation:

Component Purpose Key Consideration
Server Software Manages sync operations Keep it updated regularly
Database Stores user data and cards Perform daily backups
Security Layer Safeguards your data Use SSL/TLS encryption
Monitoring Tools Tracks server performance Monitor resource usage

To keep your server running efficiently, remember these maintenance practices:

  • Implement strong security measures
  • Regularly test the sync functionality
  • Monitor system performance closely
  • Stick to a solid backup schedule

Additional Study Tools

Your self-hosted Anki sync server gives you full control over your flashcard data, but pairing it with other tools can enhance your study routine. One option to consider is QuizCat AI, which offers features designed to streamline learning.

Here’s how QuizCat AI can complement your setup:

  • Converts study materials into flashcards
  • Generates quiz questions from your notes
  • Creates study podcasts for learning on the go

While your Anki server handles storage and syncing, QuizCat AI simplifies flashcard creation and study management. You can try QuizCat AI for just $0.99 for your first week to see how it fits into your workflow.

Related posts