Sep 9, 2024 3 min read

Mealie: Essential Tips for Successful Self-Hosting

Mealie: Essential Tips for Successful Self-Hosting
Table of Contents

Mealie is an open-source, self-hosted recipe manager and meal-planning app that allows you to organize your recipes, create shopping lists, and schedule mealsβ€”all while keeping full control of your data. Its intuitive interface, API support, and advanced customization options make it an excellent choice for tech-savvy users who value privacy and flexibility. In this guide, we'll cover everything from installing Mealie to configuring it for production use, managing backups, and leveraging its unique features.

Installing Mealie

πŸ“¦ Docker/Docker Compose Setup

Docker is the recommended way to deploy Mealie due to its simplicity and portability. Below is an example docker-compose.yml file for Mealie:


version: '3.8'

services:

mealie:

image: hkotel/mealie:latest

container_name: mealie

ports:

- "9925:80"  # Map port 80 from the container to port 9925 on the host

volumes:

- ./data:/app/data  # Persist data to the host machine

environment:

- TZ=America/New_York  # Set your timezone

- BASE_URL=http://your-domain.com  # Replace with your domain or IP

restart: unless-stopped

Run the following commands to deploy Mealie with Docker:


mkdir mealie && cd mealie

curl -o docker-compose.yml https://path-to-your-configuration/docker-compose.yml

docker-compose up -d

This will download the Mealie image, create a container, and start the service.

πŸš€ Manual Installation

For those who prefer not to use Docker, you can manually install Mealie on a Linux server. Here's how to do it:

  1. Install Python and pip (ensure Python 3.10+ is installed):

sudo apt update

sudo apt install python3 python3-pip -y

  1. Clone the Mealie repository and install dependencies:

git clone https://github.com/hay-kot/mealie.git

cd mealie

pip install -r requirements.txt

  1. Run the application:

python3 -m uvicorn mealie.app:app --host 0.0.0.0 --port 80

This method is ideal for testing or development but may require additional steps for production use.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Use Nginx as a reverse proxy to route traffic to Mealie. Create a new Nginx configuration file for your domain:


server {

listen 80;

server_name your-domain.com;

location / {

proxy_pass http://127.0.0.1:9925;  # Forward traffic to Mealie

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Save this file as /etc/nginx/sites-available/mealie and enable it:


sudo ln -s /etc/nginx/sites-available/mealie /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 -y

sudo certbot --nginx -d your-domain.com

This will automatically configure SSL/TLS and renew certificates as needed.

πŸ› οΈ Testing and Reloading Nginx

After making changes, always test and reload your configuration:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Mealie

πŸ—ƒοΈ Enabling Debug Logs

Enable debug-level logging in the data/config.yaml file:


logging:

level: DEBUG

Restart Mealie to apply the changes:


docker-compose restart mealie

πŸ“„ Viewing Logs

Access logs using Docker:


docker logs -f mealie

If running manually, check the logs directory:


tail -f /var/log/mealie.log

πŸ› οΈ Troubleshooting Common Issues

Check for common issues such as incorrect file permissions or port conflicts. For example:


sudo chown -R $USER:$USER /path/to/mealie/data

πŸ“€ Exporting Logs

Forward logs to an external log management system by setting up a Syslog or using a tool like the ELK Stack.

Backup and Restore

πŸ—‚οΈ File-Based Backups

Archive your Mealie data directory:


tar -czvf mealie-backup.tar.gz /path/to/mealie/data

To restore:


tar -xzvf mealie-backup.tar.gz -C /path/to/mealie/data

πŸ”„ Database Backups

If you're using an external database, back it up using pg_dump (PostgreSQL example):


pg_dump -U mealie_user mealie_db > mealie_db_backup.sql

Restore the database:


psql -U mealie_user mealie_db < mealie_db_backup.sql

πŸ“… Automated Backup Scripts

Set up a cron job for periodic backups:


echo "0 2 * * * tar -czvf /backups/mealie-$(date +\%F).tar.gz /path/to/mealie/data" | crontab -

Updating and Upgrading Mealie

⬆️ Updating Docker Images

Pull the latest Mealie image and redeploy:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations, pull the latest code and update dependencies:


cd mealie

git pull origin main

pip install -r requirements.txt

πŸ” Checking for Updates

Check for updates by visiting the Mealie GitHub repository or using the CLI:


docker-compose exec mealie python3 -m mealie --version

Leveraging Mealie’s Unique Features

πŸ”§ Enabling APIs

Activate the API in the configuration file:


api:

enabled: true

key: YOUR_API_KEY

Use the API for integration, e.g., fetching a recipe with curl:


curl -H "Authorization: Bearer YOUR_API_KEY" http://your-domain.com/api/recipes

🌟 Advanced Configurations

Enable advanced features such as custom themes by editing config.yaml:


theme:

primary_color: "#3498db"

secondary_color: "#2ecc71"

Restart Mealie to apply the changes.

Wrapping Up

This guide has covered everything you need to deploy, configure, and manage Mealie, from installation to backups and leveraging its unique features. By following the steps outlined above, you can enjoy a fully self-hosted recipe management platform tailored to your specific needs. Dive in, customize your setup, and enjoy the flexibility that only self-hosting can provide!

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.