How to install Snipe-IT on Ubuntu Server 20.04
What is Snipe-IT?
Snipe-IT is a free open source asset management system. This article will take you through the steps to install Snipe-IT on Ubuntu Server 20.04.
More information about Snipe-IT:
- Website: snipeitapp.com
- Documentation: snipe-it.readme.io/docs
- GitHub repository: github.com/snipe/snipe-it
Prerequisites
- Server with Ubuntu Server 20.04 installed
- User with sudo privileges
- Static IP/hostname
- SSL certificate and private key in PEM format in case you want to use HTTPS (recommended)
Installation
These steps will install Snipe-IT in the /var/www/snipe-it
directory. If you want to install Snipe-IT in a different directory you will need to change the commands accordingly.
Step 1: Installing packages
In this step the packages needed by Snipe-IT will be installed: Apache2, PHP + modules and MariaDB.
sudo apt install apache2 php libapache2-mod-php php-json php-mbstring php-tokenizer php-curl php-mysql php-ldap php-zip php-bcmath php-xml php-imagick mariadb-server
Step 2: Creating the database
Snipe-IT needs a database to store it's data, this step will take you through creating the database and a database user.
Enter the following command to start a MySQL shell as the root user.
sudo mysql -u root
Next enter the commands below to create the database snipeit_data
, create the user snipeit_data_user
and grant the user permissions on the database with a password. Afterwards enter exit
to exit out of the shell.
Please change
<password>
below to a secure password and take note of it. You will need this later.
create database snipeit_data;
create user snipeit_data_user;
grant all on snipeit_data.* to 'snipeit_data_user'@'localhost' identified by '<password>';
exit
Step 3: Creating Snipe-IT directory and downloading Snipe-IT
This step will create the /var/www/snipe-it
directory and set it's permissions. After that we pull the source code from GitHub.
The following commands will create the directory; change the owner to our sudo user (administrator in my case, might differ in your case); set the group to www-data
; set the permissions read, write and execute (7) for the owner, read and execute (5) for the group and none (0) for others; and set the inheritance of the group to newly created underlying files/directories.
sudo mkdir /var/www/snipe-it
sudo chown -R administrator /var/www/snipe-it/
sudo chgrp -R www-data /var/www/snipe-it/
sudo chmod -R 750 /var/www/snipe-it/
sudo chmod g+s /var/www/snipe-it/
Next up clone the Snipe-IT source code from the GitHub repository into the directory you just created.
git clone https://github.com/snipe/snipe-it /var/www/snipe-it
The user as which the web server runs, www-data in our case, needs write permissions on 2 folders within the /var/www/snipe-it
directory: public/uploads
and storage
.
chmod g+w /var/www/snipe-it/public/uploads
chmod g+w /var/www/snipe-it/storage
Step 4: Editing the .env configuration file
Most of the configuration of Snipe-IT is done in the .env
file. This file needs to be created first, the easiest way to do this is to create a copy of .env.example
.
cd /var/www/snipe-it
cp .env.example .env
Next we can edit the newly created .env
file. I use vi but you can use whatever text editor you prefer.
vi .env
The documentation on snipe-it.readme.io/docs/configuration describes which settings can be configured. To continue you need to change at least the following:
APP_URL=<domainname at which Snipe-IT will be running, including http:// or https://>
DB_DATABASE=snipeit_data
DB_USERNAME=snipeit_data_user
DB_PASSWORD=<password you created in step 2>
IMAGE_LIB=imagick
After changing these settings save and close the .env
file. (ESC
and then :wq
in case you're using vi)
Step 5: Installing dependencies via composer
Snipe-IT needs specific vendor packages to function. These are installed via composer.
The following commands will install composer and install the dependencies.
cd /var/www/snipe-it
curl -sS https://getcomposer.org/installer | php
php composer.phar update
php composer.phar install --no-dev --prefer-source
Step 6: Configuring the web server
The web server needs to point to the Snipe-IT files. These steps take you through configuring the web server.
Create a Apache2 VirtualHost config file.
cd /etc/apache2/sites-available
sudo vi snipe-it.conf
The following configuration is set up for the use of HTTPS. It assumes the SSL certificate is located at /etc/ssl/certs/snipe-it.pem
and the private key at /etc/ssl/private/snipe-it.key
. You can change these locations if necessary.
<VirtualHost *:443>
<Directory /var/www/snipe-it/public>
Allow From All
AllowOverride All
Options +Indexes
</Directory>
DocumentRoot /var/www/snipe-it/public
SSLEngine on
SSLCertificateFile /etc/ssl/certs/snipe-it.pem
SSLCertificateKeyFile /etc/ssl/private/snipe-it.key
</VirtualHost>
If you don't want to use HTTPS you can use the configuration below for standard HTTP.
<VirtualHost *:80>
<Directory /var/www/snipe-it/public>
Allow From All
AllowOverride All
Options +Indexes
</Directory>
DocumentRoot /var/www/snipe-it/public
</VirtualHost>
After saving the configuration file you need to enable the following Apache2 modules. ssl
is only required when using HTTPS.
sudo a2enmod rewrite
sudo a2enmod ssl
The last step is to disable the default site and enable the Snipe-IT site. And restart Apache2.
sudo a2dissite 000-default
sudo a2ensite snipe-it
sudo systemctl restart apache2
Step 7: Starting services at server startup
Automatically start the Apache2 and MariaDB service at server startup.
sudo systemctl enable apache2
sudo systemctl enable mariadb
Step 8: Snipe-IT Pre-Flight & Setup
To complete the installation you need to fill in the required fields to set up your admin user.
Now you're all set and done and you can start using Snipe-IT to manage your assets!