CentOS7结合宝塔面板安装/升级IT资产管理系统Snipe-IT

新Linux系统安装好宝塔面板,并且安装好LNMP,PHP选择7.2版本MYSQL选择5.7版本,推荐采用编译安装。

升级教程在后面。

Snipe-IT安装

①、修改PHP设置

默认禁用了部分存在危险的PHP函数,但是Composer需要使用到putenv、proc_open、pcntl_signal,还需要安装fileinfo扩展。

寻找disable_functions字符串,将后面的putenv删除后保存
删除proc_open函数的禁用
删除pcntl_signal函数的禁用
安装fileinfo扩展
②、添加网站

下载Snipe-IT源文件:https://github.com/snipe/snipe-it/archive/v4.7.8.tar.gz
GitHub:https://github.com/snipe/snipe-it/releases

打开网站目录,删除所有文件
上传Snipe-IT源文件
解压源文件
打开解压目录,剪切所有文件
返回上级目录,粘贴所有文件
③、安装Composer

SSH登陆系统(可以使用SSH软件或者宝塔的WEB SSH)

[root@bogon snipe-it]# cd /www/wwwroot/snipe-it
[root@bogon snipe-it]# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 1.9.1) successfully installed to: /www/wwwroot/snipe-it/composer.phar
Use it: php composer.phar
[root@bogon snipe-it]# cp composer.phar /usr/bin/composer
[root@bogon snipe-it]# composer config -g repo.packagist composer https://packagist.phpcomposer.com
[root@bogon snipe-it]# php composer.phar install --no-dev --prefer-source
[root@bogon snipe-it]# composer global require laravel/installer

执行php composer.phar install --no-dev --prefer-source --ignore-platform-reqs命令正常情况下会安装100多个包,需要重复执行确保安装完(国内访问可能会下载失败)。

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/更换阿里源
composer config -g repo.packagist composer https://mirrors.huaweicloud.com/repository/php/更换华为源
composer config -g --unset repos.packagist恢复初始源

④、设置目录权限
[root@bogon snipe-it]# chown -R www:www storage public/uploads
[root@bogon snipe-it]# chmod -R 755 storage public/uploads
⑤、创建配置文件,生成key
[root@bogon snipe-it]# cp .env.example .env
[root@bogon snipe-it]# vim .env

编辑.env文件,根据提供的说明找到以下行并修改

# REQUIRED: BASIC APP SETTINGS
# --------------------------------------------
APP_ENV=production
APP_DEBUG=false      # 排错的时候这个改为true
APP_URL=192.168.254.203      # 设置Snipe的域名,这里填什么就确定了用这个域名访问时才能看到图片
APP_TIMEZONE='Asia/Shanghai'
APP_LOCALE=zh-CN      # 设置默认语言


# --------------------------------------------
# REQUIRED: DATABASE SETTINGS
# --------------------------------------------
DB_CONNECTION=mysql
DB_HOST=192.168.254.203
DB_DATABASE=snipe-it      # 填写数据库名
DB_USERNAME=snipe-it      # 填写数据库用户名
DB_PASSWORD=123456      # 填写数据库密码
DB_PREFIX=null
DB_DUMP_PATH='/usr/bin'
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci


[root@bogon snipe-it]# php artisan key:generate          
**************************************
*     Application In Production!     *
**************************************

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

Application key [base64:gaY0+aP2Ye0rxu9gzCTATh2jlFyK77oq9UN/yNth2OY=] set successfully.

[root@bogon snipe-it]# mkdir /www/wwwlogs/snipeit/ 
⑥、Nginx 配置
打开宝塔面板,设置网站目录
修改配置文件
server
{
    listen 80;
    server_name 192.168.254.203;
    index index.php index.html index.htm;
    root /www/wwwroot/snipe-it/public;
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-72.conf;

    location =/.env{ 
        return 404; 
    } 
    
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        root /www/wwwroot/snipe-it/public;
        try_files $uri $uri/ =404;
        fastcgi_pass unix:/tmp/php-cgi-72.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log /dev/null;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log /dev/null; 
    }
    access_log  /www/wwwlogs/192.168.254.203.log;
    error_log  /www/wwwlogs/192.168.254.203.error.log;
}
⑦、初始化Snipe-IT
浏览器打开绑定的网址,下一步即可

方框内是必填的


设置语言


Snipe-IT升级

升级之前请备份数据库及程序(即/www/wwwroot/snipe-it/目录)

因在国内Github被qiang,所以无法通过GIT自动升级,所以只能自己手动升级了。

1、备份程序目录
[root@bogon snipe-it]# cd /www/wwwroot/
[root@bogon wwwroot]# mv snipe-it/ snipe-it-backup   #此处因后面需要重新解压程序目录,所以在此处直接重命名
2、解压新版本到/www/wwwroot/snipe-it目录(自行通过上传站点tar.gz源文件到此目录)
[root@bogon wwwroot]# tar -xzvf snipe-it-4.7.8.tar.gz -C /www/wwwroot/
[root@bogon wwwroot]# mv snipe-it-4.7.8/ snipe-it
3、拷贝旧程序的配置文件至新目录并授权
[root@bogon wwwroot]# cp -R snipe-it-backup/public/uploads/* snipe-it/public/uploads
[root@bogon wwwroot]# cp -R snipe-it-backup/storage/private_uploads/* snipe-it/storage/private_uploads
[root@bogon wwwroot]# cp -R snipe-it-backup/storage/app/backups/* snipe-it/storage/app/backups
[root@bogon wwwroot]# cp -R snipe-it-backup/.env snipe-it/
[root@bogon wwwroot]# cp -R snipe-it-backup/storage/oauth-private.key snipe-it/storage/oauth-private.key
[root@bogon wwwroot]# cp -R snipe-it-backup/storage/oauth-public.key snipe-it/storage/oauth-public.key
[root@bogon wwwroot]# chown -R www:www snipe-it/
[root@bogon wwwroot]# chmod -R 755 snipe-it/

如提示是否要覆盖.gitignore或者.gitkeep,请输入no。

4、重新执行Composer安装
[root@bogon wwwroot]# cd snipe-it/
[root@bogon snipe-it]# curl -sS https://getcomposer.org/installer | php
[root@bogon snipe-it]# php composer.phar install --prefer-source
[root@bogon snipe-it]# php composer.phar dump-autoloa
[root@bogon snipe-it]# php artisan migrate

如提示Do you really wish to run this command? (yes/no),请输入yes

5、清除缓存
[root@bogon snipe-it]# php artisan config:clear
[root@bogon snipe-it]# php artisan config:cache

到此升级完成,请访问你的网页查看页面及数据是否正常。



附上手动配置版配置文件:
server {
    listen 80;
    server_name 192.168.254.203;

    root /www/wwwroot/snipe-it/public;
    index index.php index.html index.htm;
    access_log  /www/wwwlogs/snipeit/192.168.254.203.log;
    error_log  /www/wwwlogs/snipeit/192.168.254.203.error.log;  

    location =/.env{ 
        return 404; 
    } 

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        root /www/wwwroot/snipe-it/public;
        try_files $uri $uri/ =404;
        fastcgi_pass unix:/tmp/php-cgi-72.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

你可能感兴趣的:(CentOS7结合宝塔面板安装/升级IT资产管理系统Snipe-IT)