Sep 14, 2024 3 min read

Snipe-IT: Your Self-Hosting Setup and Management Guide

Snipe-IT: Your Self-Hosting Setup and Management Guide
Table of Contents

Snipe-IT is an open-source asset management system designed to help organizations manage IT resources, including hardware, software licenses, and peripherals. As a self-hosted solution, it offers users complete control over their data, extensive customization options, and a robust API for integrations. This guide walks you through deploying, configuring, and managing Snipe-IT, covering installation, reverse proxy setup, debugging, backups, updates, and leveraging its unique features.

Installing Snipe-IT

πŸ“¦ Docker/Docker Compose Setup

Docker is the easiest way to deploy Snipe-IT. Below is a docker-compose.yml file tailored for Snipe-IT, complete with MySQL as the database backend.


version: '3.8'

services:

mysql:

image: mysql:8.0

container_name: snipeit_mysql

restart: always

environment:

MYSQL_ROOT_PASSWORD: rootpassword

MYSQL_DATABASE: snipeit

MYSQL_USER: snipeit

MYSQL_PASSWORD: snipeitpassword

volumes:

- snipeit_mysql_data:/var/lib/mysql

networks:

- snipeit_network

snipeit:

image: snipe/snipe-it:latest

container_name: snipeit_app

depends_on:

- mysql

restart: always

ports:

- "8080:80"

environment:

- APP_KEY=base64:GENERATE-KEY-HERE

- APP_URL=http://localhost:8080

- DB_HOST=mysql

- DB_DATABASE=snipeit

- DB_USERNAME=snipeit

- DB_PASSWORD=snipeitpassword

volumes:

- snipeit_uploads:/var/www/html/public/uploads

networks:

- snipeit_network

volumes:

snipeit_mysql_data:

snipeit_uploads:

networks:

snipeit_network:

Run the following commands to deploy Snipe-IT with Docker Compose:


nano docker-compose.yml

## Step 2: Deploy the containers

docker-compose up -d

## Step 3: Check the status

docker ps

πŸš€ Manual Installation

For those who prefer a manual setup on a Linux server, follow these steps:


## Step 1: Update the system and install dependencies

sudo apt update && sudo apt upgrade -y

sudo apt install -y apache2 mariadb-server php php-cli php-mbstring php-bcmath php-curl php-intl php-xml php-mysql unzip git

## Step 2: Download Snipe-IT

cd /var/www

sudo git clone https://github.com/snipe/snipe-it.git

cd snipe-it

sudo composer install --no-dev --prefer-source

## Step 3: Set permissions

sudo chown -R www-data:www-data /var/www/snipe-it

sudo chmod -R 775 /var/www/snipe-it

## Step 4: Configure the application

cp .env.example .env

nano .env  # Update database and app settings here

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Set up Nginx to route traffic to your Snipe-IT app. Here's a sample server block:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://localhost:8080;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

}

client_max_body_size 100M;

}

Save this configuration to /etc/nginx/sites-available/snipeit and enable it:


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

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your Snipe-IT app using Let's Encrypt SSL certificates.


sudo apt install certbot python3-certbot-nginx -y

sudo certbot --nginx -d yourdomain.com

sudo systemctl reload nginx

πŸ› οΈ Testing and Reloading Nginx

After making changes to the configuration, always test and reload:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Snipe-IT

πŸ—ƒοΈ Enabling Debug Logs

Enable detailed logging by modifying the .env file:


nano /var/www/snipe-it/.env

## Set APP_DEBUG to true

APP_DEBUG=true

πŸ“„ Viewing Logs

For Docker setups:


docker logs snipeit_app

For manual setups, check the Laravel logs:


tail -f /var/www/snipe-it/storage/logs/laravel.log

πŸ› οΈ Troubleshooting Common Issues

  • Database connection error: Verify .env settings for DB_HOST, DB_USERNAME, and DB_PASSWORD.

  • Permission issues: Ensure www-data owns the Snipe-IT files and directories.

πŸ“€ Exporting Logs

Send logs to an external system like ELK Stack:


docker run -d --name logstash -p 5044:5044 ...

## Configure Filebeat or a similar tool to ship logs from the container

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup critical Snipe-IT files:


sudo tar -czvf snipeit_backup.tar.gz /var/www/snipe-it

πŸ”„ Database Backups

Export the database:


mysqldump -u snipeit -p snipeit > snipeit_db_backup.sql

Restore the database:


mysql -u snipeit -p snipeit < snipeit_db_backup.sql

πŸ“… Automated Backup Scripts

Set up a cron job:


crontab -e

## Add the following line for nightly backups

0 2 * * * /usr/bin/mysqldump -u snipeit -p'snipeitpassword' snipeit > /backups/snipeit_$(date +\%F).sql

Updating and Upgrading Snipe-IT

⬆️ Updating Docker Images

Pull the latest Docker image and restart:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual setups:


cd /var/www/snipe-it

sudo git pull origin main

sudo composer install --no-dev --prefer-source

πŸ” Checking for Updates

Stay informed about new releases by monitoring the Snipe-IT GitHub repository.

Leveraging Snipe-IT’s Unique Features

πŸ”§ Enabling APIs

Enable the API in the .env file:


API_ENABLED=true

Example API call to fetch assets:


curl -X GET "http://yourdomain.com/api/v1/hardware" \

-H "Authorization: Bearer your_api_token"

🌟 Advanced Configurations

Integrate with third-party tools like Slack for notifications by using Snipe-IT’s webhook capabilities. Update the .env file:


SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url

Wrapping Up

This guide has provided a comprehensive walkthrough of deploying, configuring, and managing Snipe-IT. By following these steps, you can fully leverage its flexibility and control for effective IT asset management. Whether it's setting up backups, debugging, or using APIs, Snipe-IT empowers teams with powerful tools to streamline operations. Start exploring today!

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.