Snipe-IT was made for IT asset management, to enable IT departments to track who has which laptop, when it was purchased, which software licenses and accessories are available, and so on.
环境
- Debian 11
- PHP 7.4
- MySQL
- Nginx
参考
步骤
准备运行环境
安装 PHP、MySQL、Nginx
# PHP 7.4 apt install php7.4 php7.4-{json,pdo,mbstring,tokenizer,curl,mysql,ldap,zip,bcmath,xml,gd,fpm} # MySQL wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb dpkg -i mysql-apt-config_0.8.22-1_all.deb apt update && apt install mysql-community-server # Nginx apt install nginx rm /etc/nginx/sites-enabled/default nginx -s reload
新建数据库
CREATE DATABASE snipeit; CREATE USER 'snipe_user'@'localhost' IDENTIFIED BY 'veryStrongPassword'; GRANT ALL PRIVILEGES ON snipeit.* TO 'snipe_user'@'localhost';
获取 Snipe-IT
git clone https://github.com/snipe/snipe-it.git
配置环境变量
复制环境变量文件样例
cd snipe-it cp .env.example .env
应用相关变量
手动修改 APP_URL、APP_TIMEZONE 和 APP_LOCALE,其中
- APP_URL 填写 http:// 或 https:// + IP 或 域名,不包括末尾的斜杠
- 在 https://www.php.net/manual/en/timezones.php 查看支持的时区
- 在 https://snipe-it.readme.io/docs/configuration 查看对应的地区代码
先不更改 APP_KEY 应用密钥,完成安装 PHP 依赖的步骤后使用指令生成
数据库相关变量
按照安装数据库时的配置填写数据库地址、数据库名称、用户和密码
邮件相关变量
下图为 QQ 邮箱的配置结果
上文安装了 php7.4-gd,所以图像库选择默认的 gd,无需更改
其他变量均为选填,可以根据自身需求设置
配置目录权限
新建 sipte-it Linux 用户
useradd -g www-data snipeit
因为使用 Nginx 作为 Web Server,所以这里将 snipeit 加入了 www-data 用户组
如果使用其他 Web Server,需要根据情况修改加入的用户组
修改目录拥有者
chown -R snipeit storage public/uploads bootstrap/cache
修改写权限
chmod -R 775 storage chmod -R 775 public/uploads chmod -R 775 bootstrap/cache
最后,回到 Snipe-IT 的上级目录,将 Snipe-IT 目录的拥有者分配给 www-data 用户
chown -R www-data:www-data snipe-it
安装 PHP 依赖库
进入 Snipe-IT 的根目录,安装 composer
curl -sS https://getcomposer.org/installer | php
安装 PHP 依赖
php composer.phar install --no-dev --prefer-source
执行安装指令后,如果出现
Your lock file does not contain a compatible set of packages. Please run composer update
的错误,则改为执行
php composer.phar install --no-dev --prefer-source --ignore-platform-reqs
添加 --ignore-platform-reqs 参数,等待安装完毕
生成应用密钥
在 Snipe-IT 根目录执行
php artisan key:generate
指令会生成应用密钥并自动写入 .env 文件的 APP_KEY 变量
配置 Nginx
在 /etc/nginx/sites-available 下新建配置文件 snipe-it,写入以下内容
server { listen 80; server_name [IP or Domain]; root /path/to/snipe-it/public/; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri $uri/ =404; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
新建软链接
ln -s /etc/nginx/sites-available/snipe-it /etc/nginx/sites-enabled/
测试并重载 Ngnix
nginx -t nginx -s reload
之后可以使用浏览器访问 Snipe-IT
Snipe-IT 初始化
Snipe-IT 在安装前会检查环境变量,如果哪项有问题可以直接编辑 .env 文件,然后刷新页面排错
迁移数据库、新建用户后即可开始使用