Set-up and Maintenance of Snipe-IT in a Subdirectory

April 21, 2025 Updated on October 22, 2026

These instructions are up to date for Snipe-IT v8.8.3. Some lines may still refer to older versions, in which case simply substitute with the latest version.

These are notes on installing and configuring the self-hosted instance of Snipe-IT for the SOFT lab, in particular modifying Snipe-IT to run in a subdirectory. E.g., my-domain.tld/snipe-it, as opposed to snipe-it.my-domain.tld. This content was also discussed in a GitHub issue in Snipe-IT's issue tracker. Officially, Snipe-IT does not support running in a subdirectory despite the official documentation that suggests otherwise. I found these instructions to be incomplete to get to the desired result.

Installation

  1. I followed the standard steps to install Snipe-IT via Docker. Basically, mkdir snipeit, download a default .env file, download a docker-compose.yml, and proceed with instructions.

  2. I set up an nginx reverse proxy on the web server where the docker image is running. On SOFT's server (which was called spitter), this snippet is located in /etc/nginx/sites-enabled/spitter.

    location /snipe-it/ {
        proxy_pass http://localhost:3002/;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
    }

Based on the instructions on running Snipe-IT in a subdirectory, I made the following changes:

  1. To run Snipe-IT in a subdirectory, I modified the following settings in the .env file.

    • APP_VERSION='v8.8.0'

      • Note that, at the end of these instructions, I will replace this docker image snipe-it/snipe-it:v8.8.0 with a custom image snipe-it/snipe-it:v8.8.0-patched.
    • APP_PORT=3002

    • APP_KEY

      • See instructions on how to generate an app key.
    • APP_URL=https://spitter.soft.vub.ac.be/snipe-it

      • Note that the /snipe-it suffix is important to run snipe-it in a subdirectory.
    • LIVEWIRE_URL_PREFIX=/snipe-it

    • APP_TIMEZONE='Europe/Brussels'

    • DB_PASSWORD

    • MYSQL_ROOT_PASSWORD

    • SMTP settings:

      MAIL_MAILER=smtp
      MAIL_HOST=XXX
      MAIL_PORT=587
      MAIL_USERNAME=XXX
      MAIL_PASSWORD=XXX
      MAIL_TLS_VERIFY_PEER=true
      MAIL_FROM_ADDR=XXX
      MAIL_FROM_NAME='SOFT Snipe-IT'
      MAIL_REPLYTO_ADDR=XXX
      MAIL_REPLYTO_NAME='SOFT Snipe-IT'
      MAIL_AUTO_EMBED_METHOD='attachment'
    • APP_TRUSTED_PROXIES=XXX

      • The IP address of the server on which Snipe-IT will be hosted.

    Now it should be possible to go through the initial set-up of Snipe-it by starting the application with docker compose up -d. Note that, at the time of writing, Snipe-IT apparently does not like it when you start the application in detached mode (with the -d flag). I found it better to run this step under tmux.

  2. Following Snipe-IT's documentation, a cronjob was added to run a command every 10 minutes (documentation suggests every minute, but that seems a lot).

    crontab -e

    Add the following line:

    */10 * * * * docker compose run --rm app php artisan schedule:run >> /dev/null 2>&1
    @daily docker compose run --rm app php artisan snipeit:backup >> /dev/null 2>&1

LDAP Configuration

This is the configuration of LDAP authentication that I performed in Snipe-IT's control panel.

LDAP Server: ldaps://soft.vub.ac.be
LDAP Bind Username: uid=snipe-it,ou=People,dc=vub,dc=ac,dc=be
Base Bind DN: ou=People,dc=vub,dc=ac,dc=be
LDAP Filter: &(uid=*)(sambaAcctFlags=[U])
Username Field: uid
Last Name: sn
LDAP First Name: givenname
LDAP Authentication Query: uid=
LDAP Email: mail

Essential Docker Image Modifications

There are a couple of modifications that should be made to the docker image in order to run Snipe-IT in a subdirectory to fix a few bugs. Normally Snipe-IT will also run without these modifications, but the application is annoying because it will redirect users to the root domain (e.g., soft.vub.ac.be) at certain points, e.g., after login.

I manually made the following changes in the Snipe-IT docker container as follows. A slightly shortened variant of these instructions was given in a bug report on GitHub.

docker exec -it snipeit-app-1 /bin/bash
  1. Add a line of code to the apache2 config.

    vi /etc/apache2/sites-enabled/000-default.conf

    Add the following line of code to the VirtualHost block on the top level (e.g., as the first directive above ServerAdmin or DocumentRoot). Note that Snipe-IT's subdirectory instructions say to change it to Alias /snipe-it "/var/www/html/snipe-it/public", but in Docker the public folder is located in /var/www/html/public.

    Alias /snipe-it "/var/www/html/public"

    Restart apache:

    service apache2 restart
  2. Patch the .htaccess file.

    vi /var/www/html/public/.htaccess

    Include the following line just below the line at the top that says RewriteEngine On. This change is done according to Snipe-IT's instructions to run Snipe-IT in a subdirectory.

    RewriteBase /snipe-it

    Find the clump that contains the following 3 lines.

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    Change the second line to the following. This solves an issue with redirects, where urls with a trailing slash such as /snipe-it/users/ were being redirected to /users (without /snipe-it prefix) instead of /snipe-it/users.

    RewriteCond %{REQUEST_URI} snipe-it/(.+)/$
  3. Patch a php file.

    vi /var/www/html/app/Http/Controllers/Auth/LoginController.php

    Find a line of code, currently line 388 in v8.8.3 that says (note, use :set number to turn on line numbers in vi):

    // Redirect to the users page
    return redirect()->intended()->with('success', trans('auth/message.signin.success'));

    Change this to be the following code which reconstructs the base url + intended url path. See explanation about this code on Github.

         // Redirect to the users page
         // return Helper::safeIntended()->with('success', trans('auth/message.signin.success'));
    
         // Let the helper pull the session and perform its security validation
         $safeRedirect = Helper::safeIntended();
             
         // Extract the validated URL and isolate just the path
         $path = parse_url($safeRedirect->getTargetUrl(), PHP_URL_PATH) ?? ''; 
    
         // Rebuild the base URL from the extracted path (stripping query parameters)
         // this will automatically prepend the correct 'base url' which the original 
         // redirect did not have
         $safeRedirect->setTargetUrl(url($path));
    
         // Return the safe response with the success message
         return $safeRedirect->with('success', trans('auth/message.signin.success'));

    This solves a bug where users are redirected to the root of the domain (e.g. example.com/) instead of Snipe-IT's root (example.com/snipe-it).

  4. Exit the docker container's bash and save the modified container as a new image. Otherwise the changes are overrided every time the docker image is recreated. E.g., every time the .env file changes and you do docker compose up -d, or when an update to Snipe-IT lands.

    exit
    docker commit snipeit-app-1 snipe/snipe-it:v8.8.0-patched
  5. Change Snipe-IT's .env file to point to the image v8.8.0-patched instead of v8.8.0.

Version Upgrades

Whenever the Docker image of Snipe-IT is updated, you need to pull the image, follow the update steps of Snipe-IT (might involve migrations), and re-do the essential update modifications. For example, as of Snipe-IT v8.8.0, I performed the following steps.

  1. Create a Snipe-IT backup in Snipe-IT's configuration panel, and download the backup file.

  2. Stop Snipe-IT

    docker compose down
  3. Edit the .env file to use the new standard docker image.

    cd ~/snipeit && vi .env
    APP_VERSION='v8.8.0'
  4. Start Snipe-IT (knowing it will be broken) to get the right docker containers up and running, and to let Snipe-IT do a version upgrade.

    docker compose up -d

    At this point you can inspect the docker container's logs to see if the upgrade performed correctly (e.g., any database migrations)

    docker container logs snipeit-app-1
  5. Follow the steps above to perform the essential docker image modifications.

  6. Edit the .env file to use the patched docker image.

    cd ~/snipeit
    vi .env
    APP_VERSION='v8.8.0-patched'
  7. Start Snipe-IT.

    docker compose up -d

Additional Notes

Maintenance Mode

Snipe-IT has a maintenance mode that can be activated to disable the website for public visitors. It can be activated and deactivated as follows.

docker exec -it snipeit-app-1 /bin/bash
php artisan down
docker exec -it snipeit-app-1 /bin/bash
php artisan up

Backups

You can find the location of the Snipe-IT volume (of the docker container) as follows:

docker volume ls
docker volume inspect snipeit_storage
  • Snipe-IT's volume is stored in /home/snipe-it/.local/share/docker/volumes/snipeit_storage/_data
  • Zip files of backups are stored in /home/snipe-it/.local/share/docker/volumes/snipeit_storage/_data/dumps
RSS
https://sxv.be/blog/feed.xml