Set-up and Maintenance of Snipe-IT in a Subdirectory
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
-
I followed the standard steps to install Snipe-IT via Docker. Basically,
mkdir snipeit, download a default.envfile, download adocker-compose.yml, and proceed with instructions. -
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:
-
To run Snipe-IT in a subdirectory, I modified the following settings in the
.envfile.-
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.0with a custom imagesnipe-it/snipe-it:v8.8.0-patched.
- Note that, at the end of these instructions, I will replace this docker image
-
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-itsuffix is important to run snipe-it in a subdirectory.
- Note that the
-
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-dflag). I found it better to run this step undertmux. -
-
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 -eAdd 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: mailEssential 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
-
Add a line of code to the apache2 config.
vi /etc/apache2/sites-enabled/000-default.confAdd the following line of code to the VirtualHost block on the top level (e.g., as the first directive above
ServerAdminorDocumentRoot). Note that Snipe-IT's subdirectory instructions say to change it toAlias /snipe-it "/var/www/html/snipe-it/public", but in Docker thepublicfolder is located in/var/www/html/public.Alias /snipe-it "/var/www/html/public"Restart apache:
service apache2 restart -
Patch the
.htaccessfile.vi /var/www/html/public/.htaccessInclude 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-itFind 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-itprefix) instead of/snipe-it/users.RewriteCond %{REQUEST_URI} snipe-it/(.+)/$ -
Patch a
phpfile.vi /var/www/html/app/Http/Controllers/Auth/LoginController.phpFind a line of code, currently
line 388inv8.8.3that says (note, use:set numberto 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). -
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
.envfile changes and you dodocker compose up -d, or when an update to Snipe-IT lands.exit docker commit snipeit-app-1 snipe/snipe-it:v8.8.0-patched -
Change Snipe-IT's
.envfile to point to the imagev8.8.0-patchedinstead ofv8.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.
-
Create a Snipe-IT backup in Snipe-IT's configuration panel, and download the backup file.
-
Stop Snipe-IT
docker compose down -
Edit the
.envfile to use the new standard docker image.cd ~/snipeit && vi .envAPP_VERSION='v8.8.0' -
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 -dAt 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 -
Follow the steps above to perform the essential docker image modifications.
-
Edit the
.envfile to use the patched docker image.cd ~/snipeit vi .envAPP_VERSION='v8.8.0-patched' -
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 downdocker exec -it snipeit-app-1 /bin/bash
php artisan upBackups
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