文章目录
- 参考链接
- 一、写在前
- 二、安装操作系统
- 三、安装 PHP
- 四、下载 Snipe-IT
- 五、安装依赖
- 六、安装数据库并创建用户
- 七、安装 Snipe-IT
- 八、安装 Nginx
- 九、Web 继续安装 Snipe-IT
- 补充:
- 20250427补充:
- 最后
参考链接
How to Install Snipe-IT on Ubuntu 22.04
https://www.rosehosting.com/blog/how-to-install-snipe-it-on-ubuntu-22-04/
官方手册:https://snipe-it.readme.io/v7.1.17/docs/installation
IT打工人利器:推荐两款开源的公司固定资产管理工具
https://cloud.tencent.com/developer/article/2407425
在安装snipe-it中遇到的坑
https://www.cnblogs.com/mingxi/p/18293822
一、写在前
踩的坑多了,悟出的心得:
a.安装前一定要先找官方文档,查看软件的依赖环境,以及软件对应的版本信息
b.我使用的官方教程(默认克隆的最新版),教程里写的是PHP8.1即可,但其实最新版需要的是PHP8.2,所以导致安装失败,
二、安装操作系统
建议选择最小化安装(系统安装过程略)
apt install net-tools -y
apt -y install wget
apt install psmisc -y
apt install vim -y
apt install unzip -y
apt install curl -y
apt install git -y
apt update -y
查看系统版本
三、安装 PHP
根据Snipe-IT文档页面,v7.1.17版本要求PHP版本在8.1及以上。Ubuntu 22.04附带了PHP 8.1.2。在这一步中,我们将直接安装PHP 8.1以及所需的扩展。
# apt install php8.1-{bcmath,common,ctype,curl,fileinfo,fpm,gd,iconv,intl,mbstring,mysql,soap,xml,xsl,zip,cli}
四、下载 Snipe-IT
使用下面的命令导航到您的Web服务器的根目录。没有就新建
cd /var/www/html
然后,克隆Snipe-IT GitHub仓库并使用下面的命令将内容保存到snipe-it目录中。
git clone https://github.com/snipe/snipe-it snipe-it
//一定要注意:上面克隆的是最新版8.0.3,ubuntu版本仓库默认的PHP版本不支持,
//使用git回退版本
git clone --branch v7.1.17 https://github.com/snipe/snipe-it.git snipe-it //此操作回退的是标签,不能当做安装包使用,需要创建分支//创建分支
git switch -c snipe-it-v7.1.17
//有的说回退版本
git checkout v7.1.17 //没尝试
五、安装依赖
Composer是一个PHP包管理器,它允许我们管理我们在Snipe-IT中使用的各种供应商包的依赖关系。供应商包是其他人编写的PHP库,我们在Snipe-IT中使用它。
不需要全局安装composer,第一组命令主要用于全局安装 Composer,而第二组命令用于项目内安装 Composer 并安装项目依赖。如果你需要在多个项目中使用 Composer,全局安装更为方便;如果希望每个项目有独立的 Composer 环境,避免不同项目之间的依赖冲突,项目内安装是更好的选择。
cd /var/www/html/snipeit/
curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
cd /var/www/html/snipeit/
curl -sS https://getcomposer.org/installer | php
php composer.phar install --no-dev --prefer-source
要检查Composer版本,可以运行以下命令:
# composer -V
六、安装数据库并创建用户
Snipe-IT基于Laravel 8框架。虽然Laravel支持MySQL/MariaDB、PostgreSQL、SQLite和MSSQL,但Snipe-IT只支持MySQL/MariaDB。在这一步中,我们将从默认存储库安装MariaDB服务器。要安装MariaDB服务器,执行以下命令:
apt install mariadb-server -y
//创建数据库
mysql
mysql> CREATE DATABASE snipeit;
mysql> show databases;
mysql> create user snipeit;
mysql> GRANT ALL ON snipeit.* TO snipeit@localhost identified by '1qaz@WSX';
mysql> FLUSH PRIVILEGES;
mysql> \q
七、安装 Snipe-IT
cd /var/www/html/snipe-it
cp .env.example .env
vim .env
输入您的应用程序URL和时间区
APP_URL=http://172.0.0.110
APP_TIMEZONE='Asia/Shanghai'
APP_LOCALE='zh-CN'
然后在数据库设置下,输入您的数据库凭据
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=snipeit
DB_USERNAME=snipeit
DB_PASSWORD=1qaz@WSX
DB_PREFIX=null
设置Snipe-IT数据目录的所有权和权限。
# chown -R www-data: /var/www/html/snipe-it
# chmod -R 775 /var/www/html/snipe-it
接下来,更新Snipe-IT依赖项。
# composer update --no-plugins --no-scripts
更新Composer后,我们需要执行以下命令来安装所有应用程序依赖。(我对这步表示疑惑,但还是执行了)
# composer install --no-dev --prefer-source --no-plugins --no-scripts
在/var/www/snipe-it/。使用下面的命令生成Laravel APP Key-value。系统会自动把key填充到.env文件中。
# php artisan key:generate
八、安装 Nginx
Laravel支持多种web服务器,如Apache、Nginx或Litespeed。在这一步中,我们将安装和配置nginx。让我们先安装它,然后继续下一步。
# apt install nginx
安装后,nginx将自动启动,并且它已经配置为在重新启动时运行。所以,我们可以继续为我们的Snipe-IT网站创建一个新的nginx服务器块。
vim /etc/nginx/conf.d/snipeit.conf
在文件中插入以下内容,并确保将snipeit.yourdomain.com替换为指向服务器IP地址的实际域名或子域名。
server {listen 80;server_name snipeit.yourdomain.com; //注意替换并删除我root /var/www/html/snipe-it/public;index index.php;location / {try_files $uri $uri/ /index.php?$query_string;}location ~ \.php$ {include fastcgi.conf;include snippets/fastcgi-php.conf;fastcgi_pass unix:/run/php/php8.1-fpm.sock;fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
保存文件,然后退出。我们需要重新启动nginx来应用我们所做的更改。
# systemctl restart nginx
九、Web 继续安装 Snipe-IT
此时,我们可以导航到http://172.0.0.110并通过web浏览器继续安装。
这一步如果访问失败(页面显示:500),那大概率是安装包权限问题,
新建一个用户:useradd snipeit,
并刷新安装包权限(已反复测试,有效)
chwon -R snipeit:www-data snipe-it
chmod -R 775 snipe-it/
然后重启再尝试
Next
已创建数据库表;现在单击Next: Create User继续。
单击下一步:保存用户
到这里已安装完毕
至于更精细化的设置:LDAP、中文、使用技巧等等。请详询官手册
补充:
由于我的英文实在不好,这里我选择切换成中文。
切换中文的地方有两处:(第一处生效了)
20250427补充:
部署过程中要访问大量的github网站,大概率会因网络不同报错。不妨添加下面映射到你的hosts中,给github加加速(记得取消注释)
#185.199.108.154 github.githubassets.com
#140.82.113.22 central.github.com
#185.199.108.133 desktop.githubusercontent.com
#185.199.108.153 assets-cdn.github.com
#185.199.108.133 camo.githubusercontent.com
#185.199.108.133 github.map.fastly.net
#199.232.69.194 github.global.ssl.fastly.net
#140.82.113.3 gist.github.com
#185.199.108.153 github.io
#140.82.114.4 github.com
#140.82.112.6 api.github.com
#185.199.108.133 raw.githubusercontent.com
#185.199.108.133 user-images.githubusercontent.com
#185.199.108.133 favicons.githubusercontent.com
#185.199.108.133 avatars5.githubusercontent.com
#185.199.108.133 avatars4.githubusercontent.com
#185.199.108.133 avatars3.githubusercontent.com
#185.199.108.133 avatars2.githubusercontent.com
#185.199.108.133 avatars1.githubusercontent.com
#185.199.108.133 avatars0.githubusercontent.com
#185.199.108.133 avatars.githubusercontent.com
#140.82.113.9 codeload.github.com
#52.217.88.28 github-cloud.s3.amazonaws.com
#52.216.238.99 github-com.s3.amazonaws.com
#52.216.26.252 github-production-release-asset-2e65be.s3.amazonaws.com
#52.217.101.68 github-production-user-asset-6210df.s3.amazonaws.com
#52.217.48.84 github-production-repository-file-5c1aeb.s3.amazonaws.com
#185.199.108.153 githubstatus.com
#64.71.168.201 github.community
#185.199.108.133 media.githubusercontent.com
再或者你可以添加阿里的网站试试:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
如果频繁出现:
Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos
When working with _public_ GitHub repositories only, head here to retrieve a token:
https://github.com/settings/tokens/new?scopes=&description=Composer+on+snipeit+2025-04-27+0829
This token will have read-only permission for public information only.
When you need to access _private_ GitHub repositories as well, go to:
https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+snipeit+2025-04-27+0829
Note that such tokens have broad read/write permissions on your behalf, even if not needed by Composer.
Tokens will be stored in plain text in "/root/.config/composer/auth.json" for future use by Composer.
For additional information, check https://getcomposer.org/doc/articles/authentication-for-private-packages.md#github-oauth
Token (hidden):
这通常是因为你的项目依赖于私有 GitHub 仓库,而 Composer 需要适当的认证信息来访问这些仓库。
-
生成 GitHub 访问令牌
-
仅访问公共仓库:
访问 GitHub Token 创建页面。
我也不懂,跟着感觉选择
点击 “Generate token” 生成令牌。 -
访问私有仓库:
访问 GitHub Token 创建页面。
我也不懂,跟着感觉选择
点击 “Generate token” 生成令牌。
composer config --global github-oauth.github.com ghp_********************bTOog2ZT8G4
接着执行即可
最后
上面执行的顺序我有所调整,如果你在安装过程中遇到问题,请留言。
如果成了,给个赞鼓励一下。