Home Build a snipe-it server on Ubuntu
Post
Cancel

Build a snipe-it server on Ubuntu

Install and set up LAMP Stack\

Update Ubuntu

Update your server with:

1
sudo apt update && sudo apt upgrade -d

Install Apache

1
sudo apt install apache2 -y 

Enable Apache2 to run on system start up.

1
sudo systemctl enable apache2

Install MariaDB

1
2
3
sudo apt install mariadb-server
sudo systemctl start mysql
sudo systemctl enable mysql

Set up a root user password and secure MariaDB with:

1
sudo mysql\_secure\_installation`

Note make sure you document the password correctly. Create a database and a snipe-it user. Change to the root user with the command:

1
sudo su

Access the MariaDB console with

1
mysql -r root -p 

Create the user,database and give the user permissions to it:

1
2
3
4
5
CREATE DATABASE snipeit_data;
CREATE USER 'snipeit_user'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON snipeit.* TO 'snipeit_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Note to change the `PASSWORD`to the password you are giving to the user for the DB. Make sure you document this. If you want to double check your database has been created, use the following commands:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mysql -u user -p
MariaDB \[(none)\]> show databases;

Output:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| snipeit            |
+--------------------+
4 rows in set (0.000 sec)

Install PHP

1
sudo apt install php libapache2-mod-php php-mysql -y

You can check the version of the PHP installed with the following command;

1
2
3
4
5
root@sphinx:~# php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
   with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Install Snipe-IT

Install Extra PHP Extensions and other package required.

1
sudo apt install php-{bcmath,cli,xml,mbstring,tokenizer,curl,zip,ldap,gd} openssl curl git wget zip

Clone Snipe-IT from github and add it to the web dir.

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

Snipe-IT set up Rename the Snipe-IT variables file .env.example to .env file.

1
cp /var/www/html/snipeit/.env.example /var/www/html/snipeit/.env

Open the environment configuration file.

1
vim /var/www/html/snipeit/.env

Snipe-IT Application Settings Set the URL you will use to access your Snipe-IT, the Application language, Timezone. The URL should not have a trailing slash.

1
2
3
4
5
6
7
8
9
10
\# --------------------------------------------
\# REQUIRED: BASIC APP SETTINGS
\# --------------------------------------------
APP_ENV=production
APP_DEBUG=false
APP_KEY=ChangeMe
APP_URL=[http://servername.domain.com]
(http://servername.domain.com/)
APP_TIMEZONE='Europe/London'
APP_LOCALE=en

Snipe-IT Database Settings Set the database host, database name, user and password created above,

1
2
3
4
5
6
7
8
9
10
11
12
\# --------------------------------------------
\# REQUIRED: DATABASE SETTINGS
\# --------------------------------------------
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=snipeit
DB\_USERNAME=snipeit\_user
DB_PASSWORD=P@SSWORD
DB_PREFIX=null
DB\_DUMP\_PATH='/usr/bin'
DB_CHARSET=utf8mb4
DB\_COLLATION=utf8mb4\_unicode_ci

If you are gonna need to send emails, configure Email Server setting as well.

Install Required PHP Libraries

1
2
3
cd /var/www/html/snipeit
curl -sS https://getcomposer.org/installer | php
php composer.phar install --no-dev --prefer-source

Set dir ownership and given permission

1
chown -R www-data:www-data /var/www/html/snipeit

Generate Snipe-IT App Key The app key is a randomly generated key that app uses to encrypt data. The value generated will be assigned automatically to APP_KEY variable in the Snipe-IT configuration file.

1
2
3
4
5
6
7
8
9
10
11
12
php artisan key:generate

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*     Application In Production!     *
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Do you really wish to run this command? (yes/no) \[no\]:
\> yes

Application key set successfully.

The key generated is automatically set as the value of the APP_KEY variable in the .env file.

Configure Apache with SSL

Note you will need to enable ssl for apache with:

1
2
3
sudo a2enmod ssl

vim /etc/apache2/sites-available/snipeit.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<VirtualHost *:443>
        DocumentRoot /var/www/html/snipeit/public
        ServerName SERVERNAME.domain.com

        SSLEngine on

        SSLCertificateFile /etc/apache2/ssl/NAMEOFCERT.cer
        SSLCertificateKeyFile /etc/apache2/ssl/NAMEOFCERT.key
        SSLCertificateChainFile /etc/apache2/ssl/NAMEOFCERT.cer 

        <Directory /var/www/html/snipeit/public>
                Allow From All
                AllowOverride None
                Options None
        </Directory>

        RewriteEngine On
        RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 \[L,R=301\]
        RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-d
        RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-f
        RewriteRule ^ /index.php \[L\]

        ErrorLog ${APACHE\_LOG\_DIR}/snipeit-error.log
        CustomLog ${APACHE\_LOG\_DIR}/snipeit-access.log combined
</VirtualHost>

If you are not using SSL, then the config will be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<VirtualHost *:80> 
	DocumentRoot /var/www/html/snipeit/public
	ServerName SERVERNAME.domain.com

	<Directory /var/www/html/snipeit/public>
		Allow From All
		AllowOverride None
		Options None
	</Directory>

	RewriteEngine On
	RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-d
	RewriteCond %{REQUEST_URI} (.+)/$
	RewriteRule ^ %1 \[L,R=301\]
	RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-d
	RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-f
	RewriteRule ^ /index.php \[L\]

	ErrorLog ${APACHE\_LOG\_DIR}/snipeit-error.log
	CustomLog ${APACHE\_LOG\_DIR}/snipeit-access.log combined
</VirtualHost>

Save the configuration file and run a file syntax test.

1
apachectl configtest

If the command return, Syntax Ok, proceed. Otherwise fix the would errors.

Enable Snipe-IT site configuration.

1
2
a2ensite snipeit.conf

Enable Rewrite module.

1
a2enmod rewrite

Restart Apache

1
systemctl restart apache2

Allow through the firewall

1
2
sudo ufw allow 443
sudo ufw reload

Snipe-IT Pre-Flight & Setup Run the pre-flight setup to verify that all configurations are correct. You can access Snipe-IT pre-flight page from the URL; http://<Hostname or Address>.

This post is licensed under CC BY 4.0 by the author.