Install Snipe-IT on Ubuntu 18.04

By | January 7, 2020

I’m starting with a fresh Ubuntu 18.04 server installation. This basically follows the official snipe-it installation instructions but with details for installing on Ubuntu.

Since we’re starting with a fresh install, make sure everything is up to date:

sudo apt update
sudo apt upgrade

Install Apache

sudo apt install apache2 -y

The -y at the end of the command tells apt to just install whatever it needs to install without asking you for confirmation. Remove the -y if you want to see what is going to happen before it happens.

Point your web browser to the IP address or hostname of your server to make sure apache is up and running. You should see “Apache2 Ubuntu Default Page.”

Install PHP and the required extensions

sudo apt install php -y
sudo apt install php7.2-mbstring php7.2-curl php7.2-mysql php7.2-ldap php7.2-zip php7.2-bcmath php7.2-xml php7.2-gd -y

Install MySQL

sudo apt install mysql-server -y

Now enter the mysql shell to create the database:

sudo mysql -u root

You should now have the mysql prompt mysql>

Create the database and the user and grant permissions to the user.

mysql> create database snipeit;
mysql> create user snipe_user;
mysql> grant all on snipeit.* to 'snipe_user'@'localhost' identified by 'YOUR_DB_PASSWORD';
mysql> exit (to leave the mysql shell)

You can set whatever you want for the database name, the user name and the password. You’ll need all three later.

Install git and nano (or your favorite text editor)

Git and nano should already be installed and up to date, but just in case:

sudo apt install git nano -y

If you prefer a different text editor, install it now.

Download Snipe-IT into the web server directory

Make a directory for your snipe-it installation under the apache root directory.

sudo mkdir /var/www/html/snipe-it

Give that directory to your normal user so you can work in there without having to constantly sudo

sudo chown yourusername:yourusername /var/www/html/snipe-it

cd to the new directory and download

cd /var/www/html/snipe-it
git clone https://github.com/snipe/snipe-it .

The dot at the end of the git command prevents it making another level of snipe-it directory.

Set up the Snipe-IT config file

Copy the .env.example file to a new .env file and open it in your text editor.

cp .env.example .env
nano .env

You can find descriptions of all the configuration variables at https://snipe-it.readme.io/docs/configuration

I’ll only cover the ones you will most likely need to change:

Make sure APP_ENV is set to production and APP_DEBUG is set to false

APP_ENV=production
APP_DEBUG=false

Set your APP_URL. It’s important that this be right. From the snipe-it docs:

This is the url to your application, beginning with http:// or https:// (if you’re running Snipe-IT over SSL). This should not have a trailing slash, and you should not have public in the URL.

Images and javascript will not load correctly if this is not set to EXACTLY the URL you access your Snipe-IT app from.

APP_URL=your.domain.name

You can set APP_URL to an IP address for setup or testing and change it to another domain name later.

Set the timezone. Use one of the PHP supported time zone strings from https://www.php.net/manual/en/timezones.php

APP_TIMEZONE='YOURTIMEZONE'

Set your language. Default is English (en). See https://snipe-it.readme.io/docs/configuration#section-setting-a-language:

APP_LOCALE=en

Fill in the database settings with the database name, database user name and password you created in the mysql setup step:

DB_DATABASE=snipeit
DB_USERNAME=snipe_user
DB_PASSWORD=YOUR_DB_PASSWORD

If you want snipe-it to be able to send email, fill in the outgoing mail server settings. You’ll have to get these from your email service provider. If you are using Fastmail, see: Use Fastmail with Snipe-IT. If you are looking for a good email service provider, you might try fastmail….

Now save the file and close it. In nano you do this with:

ctrl-o enter ctrl-x

Install snipe-IT dependencies

Make sure you are still in the snipe-it directory. If you are following this guide it will be /var/www/html/snipe-it

cd /var/www/html/snipe-it

Snipe-IT uses a PHP dependency manager called Composer to manage its dependencies so install it and then install the dependencies:

curl -sS https://getcomposer.org/installer | php
php composer.phar install --no-dev --prefer-source

This might take a few minutes so go have a cup of tea. If you need some tea and you also want to help me pay my Internet bill so I can make more guides like this (at no additional cost to you), you can buy some tea through my Amazon affiliate link.

Generate your app key

php artisan key:generate

This will generate an encryption key and set APP_KEY in your .env file. Copy the key and save it somewhere.

Grant appropriate filesystem permissions so apache can access the files

(Note, I’m not a Linux filesystem permissions super expert person. Setting permissions incorrectly can have negative consequences. The way I am doing it here seems reasonable to me, but someone else might have a different opinion):

First make put all the files into the www-data group

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

Now remove group write permission from the files. There’s no reason for apache to be able to write to all these files:

sudo chmod -R g-w /var/www/html/snipe-it

Now add back write permission for the areas we want Snipe-IT to be able to write to:

sudo chmod -R g+w /var/www/html/snipe-it/storage
sudo chmod -R g+w /var/www/html/snipe-it/public/uploads

Configure the server

I’m going to set this up as a name-based virtual host in apache. According to the docs, Snipe-IT really wants to be run on its own domain or subdomain, rather than in a subdirectory. If subdirectory is your only option, see https://snipe-it.readme.io/docs/subdirectories

Copy the default vhost file and open the copy in your text editor.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/snipe-it.conf
sudo nano /etc/apache2/sites-available/snipe-it.conf

Edit the file to look like this:

<VirtualHost *:80>

        #Use the email address of whoever is responsible for this server
        ServerAdmin you@youremail.domain

        #this should be the public directory under your snipe-it installation
        DocumentRoot /var/www/html/snipe-it/public

        #this should match the APP_URL in the .env configuration file
        ServerName 192.168.1.161

        <Directory /var/www/html/snipe-it/public>
                Allow From All
                AllowOverride All
                Options -Indexes
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save the file and close your text editor (for nano, ctrl-o enter ctrl-x).

Disable the old default vhost and enable your new vhost

sudo a2dissite 000-default.conf
sudo a2ensite snipe-it.conf

Also enable mod_rewrite

sudo a2enmod rewrite
sudo systemctl reload apache2

Start the Application

Now point your web browser at the address of your web server. You should get the Snipe-IT Pre-Flight. If you did everything right, your Pre-Flight check should be all green check marks. If you set up email sending, hit the “Send Test” button to test it.

If all of that works out, hit the button at the bottom that says “Next: Create Database Tables”

Every time I do this, I get a page with url http://my.domain.name/setup/migrate? that says

“Whoops, looks like something went wrong.”

But when this happens, I just reload the page and get back to step 2 of the Snipe-IT Pre-Flight with a message that says “There was nothing to migrate. Your database tables were already set up!” I’m not sure why this happens, and it doesn’t seem to have caused any problems, so I have just carried on like it didn’t happen.

Now click the button the says “Next: Create User”

In this step, fill in the information for the admin user and also the other settings.

Once everything is filled in, hit the “Next: Save User” button and you should be at the snipe-it dashboard. Have fun managing your assets.

Enable HTTPS with Let’s Encrypt (Optional, but highly recommended)

You could stop here, but you should enable https on the site. If you have your Snipe-IT installation facing the Internet you can use let’s encrypt to do this.

You can follow the instructions at https://certbot.eff.org/lets-encrypt/ubuntubionic-apache.html which I will reproduce here (with my notes) for your convenience.

Add certbot PPA (Personal Package Archive)

sudo add-apt-repository ppa:certbot/certbot

Install certbot

sudo apt install certbot python-certbot-apache

Run certbot (this is the automatic setup version, see the certbot link above if you want the more conservative version)

sudo certbot --apache

Make sure automatic renewal works

sudo certbot renew --dry-run

When it’s done, edit your snipe-it .env to reflect the url change.

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

Update APP_URL with the https

APP_URL=https://your.domain.name

Now navigate to your site and see the padlock showing you have a working TLS certificate.

Not sure this is necessary, but restart apache just in case

sudo systemctl restart apache2

Done

If this guide was useful to you consider supporting me in one of the following ways (these are affiliate links which means if you go there and get something, they will pay me a small fee (at no additional cost to you) for sending you over):

  • Buy whatever you would normally buy at Amazon.com. Maybe you want a Raspberry Pi to use as a Snipe-IT server.
  • Download and use the Brave web browser. Brave is a privacy-focused web browser and an experiment in a different way of monetizing web content.
  • Try out Fastmail. I’ve been using Fastmail as my email provider for almost 20 years. The down side of Fastmail is that it isn’t free (I pay money for it). The up side is that, since they get paid by their users, they don’t sell us out to advertisers like the “free” email services do. Also, the features.