Jul 21, 2024 3 min read

Standard Notes: The Ultimate Self-Hosting Setup

Standard Notes: The Ultimate Self-Hosting Setup
Table of Contents

Standard Notes is a secure, open-source note-taking application designed with privacy and simplicity in mind. It allows users to self-host their own instance, ensuring complete control over their data while offering extensive customization options. In this guide, we’ll explore the essential steps to deploy, configure, and manage a self-hosted Standard Notes server, covering installation, reverse proxy configuration, logging, backups, updates, and leveraging its unique features.

Installing Standard Notes

πŸ“¦ Docker/Docker Compose Setup

Using Docker Compose is one of the easiest ways to deploy Standard Notes. Below is a docker-compose.yml file to set up a self-hosted instance of the Standard Notes sync server.


version: '3.8'

services:

standardnotes:

image: standardnotes/self-hosted:latest

container_name: standardnotes

restart: unless-stopped

ports:

- "3000:3000" # Map port 3000 for external access

environment:

- NODE_ENV=production

- SERVER_URL=https://yourdomain.com # Replace with your domain

- DB_HOST=mysql # Database hostname

- DB_PORT=3306 # Database port

- DB_USER=standardnotes # Database username

- DB_PASSWORD=yourpassword # Database password

- DB_DATABASE=standardnotes # Database name

- REDIS_HOST=redis # Redis hostname

- REDIS_PORT=6379 # Redis port

depends_on:

- mysql

- redis

volumes:

- ./data:/data # Persist data locally

mysql:

image: mysql:8.0

container_name: mysql

restart: unless-stopped

environment:

- MYSQL_ROOT_PASSWORD=yourrootpassword

- MYSQL_DATABASE=standardnotes

- MYSQL_USER=standardnotes

- MYSQL_PASSWORD=yourpassword

volumes:

- ./mysql_data:/var/lib/mysql

redis:

image: redis:latest

container_name: redis

restart: unless-stopped

volumes:

- ./redis_data:/data

Deploy the stack with the following commands:


mkdir standardnotes && cd standardnotes

nano docker-compose.yml # Paste the above configuration

docker-compose up -d

πŸš€ Manual Installation

For a manual installation on a Linux server, follow these steps:

  1. Install Node.js, MySQL, and Redis:

sudo apt update && sudo apt install -y nodejs npm mysql-server redis-server

  1. Clone Standard Notes from GitHub:

git clone https://github.com/standardnotes/syncing-server.git

cd syncing-server

  1. Install dependencies and build the app:

npm install

npm run build

  1. Configure environment variables:

cp .env.example .env

nano .env # Update your environment variables, such as DB credentials

  1. Start the server:

npm start

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To serve Standard Notes via Nginx, create a server block file:


sudo nano /etc/nginx/sites-available/standardnotes

Add the following content:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://127.0.0.1:3000;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection 'upgrade';

proxy_set_header Host $host;

proxy_cache_bypass $http_upgrade;

}

}

Enable the configuration and reload Nginx:


sudo ln -s /etc/nginx/sites-available/standardnotes /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your site with Let's Encrypt:


sudo apt install certbot python3-certbot-nginx

sudo certbot --nginx -d yourdomain.com

Automate certificate renewals:


sudo crontab -e

0 0 1 * * certbot renew --quiet

Logging and Debugging Standard Notes

πŸ—ƒοΈ Enabling Debug Logs

Enable debug logging by updating the .env file in your Standard Notes installation:


DEBUG=true

Restart the server to apply the changes:


docker-compose restart

## Or, for manual installation

npm start

πŸ“„ Viewing Logs

Access Standard Notes logs with the following commands:

  • For Docker:

docker logs standardnotes

  • For manual installations:

tail -f /path/to/your/logfile.log

πŸ› οΈ Troubleshooting Common Issues

Common issues, such as database connection errors, can often be identified in the server logs. Look for errors like:


Error: Cannot connect to the database

Verify that MySQL and Redis are running:


sudo systemctl status mysql

sudo systemctl status redis

Backup and Restore

πŸ—‚οΈ File-Based Backups

To back up data volumes (Docker), run:


tar -czvf standardnotes-backup.tar.gz ./data ./mysql_data ./redis_data

πŸ”„ Database Backups

Back up the MySQL database manually:


mysqldump -u standardnotes -pstandardnotes_password standardnotes > db_backup.sql

Restore the database:


mysql -u standardnotes -pstandardnotes_password standardnotes < db_backup.sql

πŸ“… Automated Backup Scripts

Set up a cron job for periodic backups:


crontab -e

## Add the following line for daily backups

0 2 * * * tar -czvf /path/to/backups/standardnotes-$(date +\%F).tar.gz /path/to/data

Updating and Upgrading Standard Notes

⬆️ Updating Docker Images

Pull the latest Docker image and redeploy:


docker-compose pull

docker-compose down

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations, update the codebase and rebuild:


git pull origin main

npm install

npm run build

Restart the server:


npm start

Leveraging Standard Notes’s Unique Features

πŸ”§ Enabling APIs

Standard Notes supports APIs for sync and data management. To enable them, ensure your .env file contains the correct SERVER_URL and run the app. Use curl to interact with the API:


curl -X POST https://yourdomain.com/items -H "Authorization: Bearer <token>"

🌟 Advanced Configurations

To customize your installation, update the .env file to enable features like email notifications or integrations, then restart the server.

Wrapping Up

This guide covered deploying and managing Standard Notes, from installation to backups, reverse proxies, and advanced configurations. By self-hosting Standard Notes, you gain full control over your data and can tailor the app to your needs. Start implementing the code examples above to harness the power of this secure and customizable note-taking solution.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.