Snipe-IT Centos7 安装部署
安装时间:2023年11月21
OS:CentOS7.9 2002
注:非root用户请自行加 sudo
安装必要的epel 和其他工具
sudo yum -y install epel-release vim net-tools wget sudo yum update -y
启用epel和添加PHP 7.4 Remi存储库
yum -y install epel-release yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安装yum-utils
yum -y install yum-utils
默认存储库PHP 5.4,禁用此repo并启用PHP 7.4
yum-config-manager --disable remi-php54 yum-config-manager --enable remi-php74
安装PHP7
yum -y install php php-cli php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pdo php-pecl-apcu php-pecl-apcu-devel php-fpm php-openssl php-tokenizer php-mysql php-ldap php-fileinfo php-dom
检查安装的版本
php -v
安装Apache
yum install -y httpd httpd-devel
修改http.conf文件
vim /etc/httpd/conf/httpd.conf
在AddType application*后面加如下一行
AddType application/x-httpd-php .php .phtml
大概在第285行左右添加,添加后如下:
272 #AddType application/x-gzip .tgz 273 # 274 # AddEncoding allows you to have certain browsers uncompress 275 # information on the fly. Note: Not all browsers support this. 276 # 277 #AddEncoding x-compress .Z 278 #AddEncoding x-gzip .gz .tgz 279 # 280 # If the AddEncoding directives above are commented-out, then you 281 # probably should define those extensions to indicate media types: 282 # 283 AddType application/x-compress .Z 284 AddType application/x-gzip .gz .tgz 285 AddType application/x-httpd-php .php .phtml
在DirectoryIndex index.html加上index.php
DirectoryIndex index.php index.html
添加后如下:
157 </Directory> 158 159 # 160 # DirectoryIndex: sets the file that Apache will serve if a directory 161 # is requested. 162 # 163 <IfModule dir_module> 164 DirectoryIndex index.php index.html 165 </IfModule>
确保httd.conf文件中包含以下字段,如不包含则加入此字段
LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
添加后如下:
53 # Example: 54 # LoadModule foo_module modules/mod_foo.so 55 # 56 Include conf.modules.d/*.conf 57 LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so 58 #
重启httpd服务+开机自启
systemctl restart httpd
systemctl enable httpd
检验httpd的PHP支持
echo "<?php phpinfo(); ?>" >> /var/www/html/index.php
重启httpd服务,添加防火墙例外之后在浏览器输入服务器地址可访问本机php信息网页
systemctl restart httpd firewall-cmd --permanent --zone=public --add-port=80/tcp systemctl restart firewalld
同网段下浏览器输入本机地址可访问本机php信息网页
Mariadb的安装
yum install -y mariadb mariadb-server systemctl start mariadb
systemctl enable mariadb
配置数据库
默认情况下,MariaDB附带一个空白的根密码和一个不安全的配置,以便于配置。它带有一个安全的安装脚本,旨在设置root密码并使用安全的默认值配置服务器。
sudo mysql_secure_installation
当系统提示输入 root 的当前密码时,请按“无”。Enter
当系统要求您提供新的 root 密码时,请确保使用安全密码。该密码将在管理数据库指南的后续步骤中使用。因此,建议将此密码存储在安全的地方。
回答或按所有剩余的提示。'Y’ENTER
创建数据库
$ sudo mysql -u root -p 创建数据 CREATE DATABASE snipeit; 创建用户名和密码 CREATE USER snipeit@localhost IDENTIFIED BY 'snipeit'; \\密码自定义,也可以先用这个,创建完之后改 授予新用户相关权限 GRANT ALL PRIVILEGES ON snipeit.* TO snipeit@localhost; 加载配置,使其生效 FLUSH PRIVILEGES;
如需修改密码,使用以下命令进行修改
# 选择数据库 use snipeit # 修改密码 update user set password=password('snipeit!@#') where user='snipeit'; # 刷新权限 flush privileges;
启动php-fpm+开机自启
systemctl start php-fpm systemctl enable php-fpm
安装Snipit
安装composer(Composer是PHP的依赖管理器)
curl -sS https://getcomposer.org/installer | php mv /root/composer.phar /usr/bin/composer
snipeit的安装
cd /var/www yum install -y git git clone https://github.com/snipe/snipe-it snipe-it #这里建议用科技上网
snipeit的配置
cd /var/www/snipe-it sudo cp .env.example .env vim .env
按以下修改
APP_URL=http://本机地址 #按实际设置填入地址 APP_TIMEZONE='Asia/Shanghai' #填入国家地址 DB_DATABASE=snipeit #数据库名称 DB_USERNAME=snipeit #数据库用户名 DB_PASSWORD=324215 #数据库密码
非调试模式下,请确保
APP_DEBUG=false
调试的时候请更改为true
更改目录权限
chown -R apache:apache storage public/uploads chmod -R 755 storage chmod -R 755 public/uploads
安装PHP依赖
composer install --no-dev --prefer-source #这个需要的时间巨长,有部分会失败,结束后反复执行这个命令,直到所有依赖都安装完
生成app_key
php artisan key:generate
如下:
[root@localhost snipe-it]# php artisan key:generate ************************************** * Application In Production! * ************************************** Do you really wish to run this command? (yes/no) [no]: > yes \\输入yes,回车 Application key set successfully.
修改Apache配置文件,创建虚拟主机
vim /etc/httpd/conf.d/snipeit.example.com.conf
粘贴如下信息:
<VirtualHost *:80> ServerName snipeit.example.com DocumentRoot /var/www/snipe-it/public <Directory /var/www/snipe-it/public> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
重启Apache服务
systemctl restart httpd
关闭SELINUX
#临时关闭selinux setenforce 0 #永久关闭selinux vim /etc/sysconfig/selinux SELINUX=enforcing 改为 SELINUX=disabled
OK,访问http://服务器地址即可。
故障记录:
1,创建资产型号报错500的解决办法:
chmod -R 777 /var/www/html/snipeit/bootstrap/cache
以上方法不推荐,不是最佳解决方法。如有其他方案欢迎投稿,谢谢!
参考官方KB:https://github.com/snipe/snipe-it/issues/11203
2,配置Linux网络Dai理
临时设置: export http_proxy=x.x.x.x:7890 export https_proxy=x.x.x.x:7890 临时取消 unset http_proxy unset https_proxy 如果想要使代理服务器永久生效,可以修改 /etc/profile文件 ,在profile 中添加或者删除。
参考文献:
https://snipe-it.readme.io/docs
https://www.cnblogs.com/zhouxinjx/p/17574610.html
https://blog.csdn.net/cjenjingwen/article/details/126760742