CentOS
centos7
OSS
snipeit

CentOS7 に Snipe-IT を導入

Snipe-IT とは

環境

cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

uname -a
Linux hostname 3.10.0-693.5.2.el7.x86_64 
#1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

nginx -v
nginx version: nginx/1.13.6

mysql --version
mysql  Ver 15.1 Distrib 10.1.28-MariaDB, for Linux (x86_64) using readline 5.1

rpm -qa | grep Mari
MariaDB-common-10.1.28-1.el7.centos.x86_64
MariaDB-client-10.1.28-1.el7.centos.x86_64
MariaDB-server-10.1.28-1.el7.centos.x86_64

php -v
PHP 7.0.25 (cli) (built: Oct 24 2017 18:17:05) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

php-fpm -v
PHP 7.0.25 (fpm-fcgi) (built: Oct 24 2017 18:18:32)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

インストール手順

step1 : nginx

# install
yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum --enablerepo=epel install nginx

# auto start
systemctl enable nginx
systemctl start nginx
  • httpd(80番ポート) への通信を許可
sudo firewall-cmd --add-service=http --zone=public --permanent
success

sudo  firewall-cmd --reload
success

step2 : php, php-fpm, php-process

  • php71 はだめらしい
yum --enablerepo=remi-php70 install php php-fpm php-mbstring php-pdo php-mysqlnd php-mcrypt php-gd php-zip
  • php-fpm の実行ユーザとグループの変更
" /etc/php-fpm.d/www.conf
user = nginx
group = nginx
  • php-process
    • php upgrade.php するために必要
# 私の場合は 7.0.25-1.el7.remi だから
wget https://rpms.southbridge.ru/rhel7/php-7.0/x86_64/php-process-7.0.25-1.el7.remi.x86_64.rpm
sudo rpm -ivh php-process-7.0.25-1.el7.remi.x86_64.rpm
  • サービス化
sudo systemctl enable php-fpm
sudo systemctl start php-fpm

step3 : MariaDB

  • 10.2 はダメらしい
" /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
  • インストールとサービス自動化
# install
yum install mariadb mariadb-server

# auto start
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
  • セットアップ
# setup
mysql_secure_installation
  • DB と ユーザ作成
# mysql -u root -p
MariaDB [(none)]< create database snipeit;
MariaDB [(none)]< grant all on snipeit.* to root@localhost identified by '*****';
MariaDB [(none)]< flush privileges;
MariaDB [(none)]< exit;

step4 : Snipe-IT

  • 公式推奨は git clone
sudo git clone https://github.com/snipe/snipe-it /var/www/snipe-it

セットアップ

cd /var/www/snipe-it
sudo cp .env.example .env
  • 変更した箇所のみ表示
" /var/www/snipe-it/.env

# REQUIRED: BASIC APP SETTINGS
" 不具合の原因調査に有効
APP_DEBUG=true

" Snipe-IT をインストールしたマシンのアドレス
APP_URL= null

APP_TIMEZONE='Asia/Tokyo'
fAPP_LOCALE=ja

# REQUIRED: DATABASE SETTINGS
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=snipeit
DB_USERNAME=root
DB_PASSWORD=****
DB_PREFIX=null
DB_DUMP_PATH='/usr/bin'
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci

パーミッション

# /var/www/snipe-it
chown -R nginx:nginx /var/www/snipe-it
chmod -R 755 storage
chmod -R 755 storage/private_uploads
chmod -R 755 public/uploads

step5 : composer

  • /var/www/snipe-it に直接ダウンロードできなかった
cd ~
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /var/www/snipe-it
sudo php composer.phar install --no-dev --prefer-source

step6 : APP_KEY

# /var/www/snipe-it
sudo php artisan key:generate

step7 : nignx.conf

# /etc/nignx/nginx.conf
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  snipeit;
        root         /var/www/snipe-it/public;
        index index.php index.html index.htm;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            try_files $uri $uri/ /index.php$is_args$args;   ← 追記
        }
        ↓ 追記
        location ~ \.php$ {
            try_files $uri $uri/ =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
sudo systemctl reload nginx

Snipe-IT

  • top page

snipe_top.png

  • version
Snipe-IT version php version Laravel version
v4.1.3 build 48 (g74aa562) 7.0.25 5.4.29

課題

日本語で pdf 保存する際の注意点

  • デフォルトでは文字化けした・・・
  • pdf 化するときは jsPDF を使っているらしい

注意点

パーミッション

sudo chcon -R -t httpd_sys_rw_content_t /var/www/laravel/storage
sudo chcon -R -t httpd_sys_rw_content_t /var/www/laravel/bootstrap/cache

メール

sudo setsebool -P httpd_can_network_connect on
sudo setsebool -P httpd_can_sendmail on

参考