ブログタイトル募集中の新人SE記

ネットの片隅で非力を嘆く

【Mac】Raspberry Pi 3 に CentOS7 を入れてみた ①

f:id:SH000N:20161026013844j:plain

今回やりたいこと

Raspberry Pi 3にCentOSを入れる

背景

結果:正直どっちでもよかったかな

  • 特にこだわりない方は公式ページから配布されているOS使うのが吉
    • スタートアップの手順もググればたくさん出てきます
    • 実際おバカな僕ですら数時間でセットアップできました

まあやってしまったのでcentosの入れ方書いていきます

実行環境

マシン

購入したもの

自宅にあるもので賄ったもの

  • HDMIケーブル
  • ディスプレイ

手順

microSDにCentOSイメージを書き込む

shon-blo.hatenablog.com

RasberryPiでCentOSを起動、初期設定いろいろ

shon-blo.hatenablog.com

sshmacからラズパイに接続

shon-blo.hatenablog.com

mac × eclipse にTomcat及びTomcatプラグインを設定

Tomcatをダウンロード

ダウンロード

  1. Tomcatのサイトにアクセス→tomcat
  2. 画面左側の「Download」にある好きなバージョンをクリック f:id:SH000N:20160911065452p:plain
  3. zipファイルを取得 f:id:SH000N:20160911070535p:plain
  4. 解凍したファイルを好きなディレクトリに移動しておく

tomcat設定

  1. eclipse→環境設定をクリック
  2. サーバ▷ランタイム環境▷追加を選択 f:id:SH000N:20160911075603p:plain
  3. Apachetomcatを選択し「次へ」をクリック f:id:SH000N:20160911075823p:plain
  4. Tomcatインストール・ディレクトリの欄にあらかじめインストールしておいたtomcatディレクトリを入力し、「完了」をクリック f:id:SH000N:20160911080441p:plain

プラグインを取得

  1. 「ヘルプ」→「Eclipseマーケットプレースを開く」をクリック f:id:SH000N:20160911071806p:plain
  2. 画面上部の検索バーから「Tomcat」と入力し検索
    • ネコのマークのやつをインストール f:id:SH000N:20160911072736p:plain
  3. eclipseを再起動
  4. 3匹のネコf:id:SH000N:20160911073712p:plainツールバーに現れる
    • 右から「起動」「停止」「再起動」

完了

  • 起動のネコをクリック
    • コンソールの最終行に情報: Server startup in 1814 msと表示されれば成功
    • localhost:8080にアクセスし下記のように表示されれば成功 f:id:SH000N:20160911080411p:plain

以上。お疲れ様でした

macでeclipseを日本語化したった

eclipse設定

ダウンロード

  1. 画面右上の「DOWNLOAD」をクリック f:id:SH000N:20160911050528p:plain
  2. 画面左下の「DOWNLOAD 64bit」をクリック f:id:SH000N:20160911050547p:plain
  3. 画面中央の「DOWNLOAD」をクリック f:id:SH000N:20160911050613p:plain

日本語化

日本語化に必要なpleiadesを入手

  1. 画面下部の「Pleiadesプラグイン・ダウンロード」内の「安定版」をクリック f:id:SH000N:20160911051604p:plain
  2. 画面下部の「pleiades_1.7.0.zip」をクリックしダウンロード f:id:SH000N:20160911051617p:plain
  3. ダウンロードが自動で始まらない場合はリンクをクリック f:id:SH000N:20160911051628p:plain

    入手したpleiadeseclipseに設定

  4. pleiadesのzipファイルを解凍
  5. その中にある「features」「plugins」をそれぞれ 7. に丸々コピー f:id:SH000N:20160911051639p:plain
  6. eclipseを右クリックし「パッケージの内容を表示」をクリック f:id:SH000N:20160911063141p:plain
  7. Contents/Eclipse/featires及びContents/Eclipse/pluginに 5. を貼り付け f:id:SH000N:20160911051650p:plain
  8. Contents/Eclipse/eclipse.iniを編集 f:id:SH000N:20160911051730p:plain
  9. eclipse.iniの最終行に下記を追加
-Xverify:none
-javaagent:../Eclipse/plugins/  jp.sourceforge.mergedoc.pleiades/pleiades.jar

完了

  • eclipseを起動
  • 下図のように日本語で表示されていれば完了 f:id:SH000N:20160911062741p:plain
  • お疲れ様でした

DB周りのメモ(mysql)

DB設定

mysqlに接続

  • 接続
$ mysql -u <UserName> -p
  • 'Enter password:'と聞かれるのでパスワードを入力する
Enter password: <Password>
  • 切断
mysql> quit;

ユーザ

  • ユーザの確認
mysql> select User,Host from mysql.user;
+---------+-----------+
| User    | Host      |
+---------+-----------+
| root    | 127.0.0.1 |
| root    | ::1       |
| root    | localhost |
+---------+-----------+
3 rows in set (0.00 sec)
  • ユーザ作成 ホスト名を省略すると'<ユーザ名>'@''%(ワイルドカード)'と記述したものとして扱われる
mysql> create user '<UserName>'@'<HostName>' identified by '<Password>';
  • ユーザの削除 間違えたコマンドで不要なユーザが大量生産されたので削除しましたw
mysql> drop user '<UserName>'@'<HostName>';
  • 権限付与
GRANT <操作名> ON <データベース名>.<テーブル名>TO <ユーザ名>@<ホスト名> IDENTIFIED BY '<パスワード>';

データベース

  • データベースの確認
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
  • データベース作成
mysql> create database <DatabaseName>;
  • 操作するデータベースを選択
mysql> use <DatabaseName>;

テーブル

  • テーブルの確認
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
=============================
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

マイグレーション

$ php artisan make:migration <マイグレーションファイル名> --create=<作成したいテーブル名>
<?php
 
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
 
class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     * テーブル作成の手続きを記述
     * 
     * @return void
     */
    public function up()
    {
        Schema::create('<作成したいテーブル名>', function (Blueprint $table) {
            //下記に作成したいカラムを記述
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }
 
    /**
     * Reverse the migrations.
     * upメソッドの内容を元に戻す手続きを記述
     * 
     * @return void
     */
    public function down()
    {
        Schema::drop('<作成したいテーブル名>');
    }
}
$ php artisan migrate

シーダー

  • db:seedコマンドで実行されるdatabase/seeds/DatabaseSeeder.phpを編集
<?php
 
use Illuminate\Database\Seeder;
 
class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //テーブルごとのSeederクラスをcallメソッドで呼ぶ
        $this->call(UsersTableSeeder::class);
    }
}
  • 各テーブルごとのシーダーファイル作成
$ php make:seeder <シーダーファイル名>
  • 作成されたシーダーファイル内のrunメソッドにデータ挿入処理を記述
<?php
 
use Illuminate\Database\Seeder;
 
class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //データクリア
        DB::table('users')->delete();
        //データ挿入処理
        $users = [];
        for($i  = 1; $i <= 20; $i++){
            $users[] = [
                'name' => '名前'.$i,
                'email' => 'mail'.$i.'@email.com',
                'password' => 'pass'.$i
            ];
        }
        foreach($users as $user){
            DB::table('users')->insert($user);
        }
    }
}
  • シーダーの実行
$ php artisan db:seed
Seeded: UsersTableSeeder
  • なにしても動かなかったから下記コマンド実行したら動いためも
$ composer dump-autoload

vagrantを使った仮想環境で新規laravelプロジェクトを作成、Gitの設定までしてみた(Windows)

はじめに

やりたいこと

  • 仮想環境の構築
  • laravelを使った新規プロジェクト作成
  • GitHubでプロジェクトを管理

実行環境

事前準備

仮想環境の構築

vagrantの導入(ホスト側)

  • ディレクトリを作成、そのディレクトリに移動
> mkdir .\Users\<ユーザ名>\vagrant\Develop
> cd .\Users\<ユーザ名>\vagrant\Develop
  • vagrantBoxを追加
> vagrant box add <Box名> <Boxのurl>
  • Boxの確認
> vagrant box list
  • 追加したvagrantBoxを使ってVagrantfileを生成
> vagrant init develop
  • ホストを自動で追加削除してくれるプラグインをインストール
> vagrant plugin install vagrant-hostsupdater
# -*- mode: ruby -*-
# vi: set ft=ruby :
 
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
 
Vagrant.configure(2) do |config|
  config.vm.box = "develop" //ここは自動で書かれていたものを残す
  config.vm.hostname = "develop"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.hostsupdater.aliases = ["develop","develop"]
  config.vm.synced_folder ".", "/vagrant", mount_options: ['dmode=777','fmode=777']
end
  • 起動
> vagrant up

マウントに失敗するときは下記のプラグインをインストール

> vagrant plugin install vagrant-vbguest

TeraTermssh接続

  • vagrant up ので表示されるホストとポート番号を使う
  • ユーザ名/パスワード

nginxの設定(ゲスト側)

  • ディレクトリ移動
$ cd /etc/nginx/conf.d/
  • confファイル作成
$ sudo vi <Vagrantfileに記載したバーチャルホスト名>.conf
  • 下記に書き換えて編集
server {
    # listenするポート番号を記述する
    listen       80;
    # バーチャルホスト名を記述する
    server_name  <Vagrantfileに記載したバーチャルホスト名>;
    # ドキュメントパスを記述する
    root /vagrant/<任意のディレクトリ名>/public;
    # デフォルト要求ファイル名を記述する
    index index.php;

    # 末尾が.phpの要求を対象とする設定
    location ~* \.php$ {
        # /usr/local/php7/etc/php-fpm.d/www.confに設定しているIPとポートを指定する
        # (例)listen = 127.0.0.1:9000
        fastcgi_pass 127.0.0.1:9000;

        # FastCGIサーバは自動index付与をサポートしていない
        # その為、Nginx側が末尾が"/"だった場合fastcgi_indexの値を末尾に付与する
        fastcgi_index  index.php;

        # PHP-FPMに渡されるドキュメントパス
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        # その他のFastCGI関連の設定は以下に追加
        include         fastcgi_params;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
}

laravelで新規プロジェクト作成

composerのインストール

  • composerをインストール
$ curl -sS https://getcomposer.org/installer | php
  • composerを移動
$ sudo mv composer.phar /usr/local/bin/composer

laravelプロジェクトをインストール

composer create-project laravel/laravel --prefer-dist <任意のプロジェクト名>

GitHubでプロジェクト管理

gitの設定

github側でリポジトリ作成

  • ■のところに任意のリポジトリ名をいれて「Create repository」をクリック f:id:SH000N:20160320234336p:plain

ゲスト側でgitの設定

$ echo "# develop" >> README.md
  • .git作成
$ git init
  • gitの設定
$ git config --global user.name "<ユーザ名>"
$ git config --global user.email "<メールアドレス>"
  • gitコマンドの表示に色を付ける設定
$ git config --global color.ui auto
  • コミットファイルにreadme.mdを追加
$ git add readme.md
  • laravelもデフォルトファイルも全部コミットファイルに追加
$ git add <必死に全ファイル>

(ぜっったいにもっといい手法あります) - 変更内容をコミット

$ git commit -m "first commit"
$ git remote add origin https://github.com/<チーム名>/<リポジトリ名>.git
  • コミット履歴をリモートにプッシュ
$ git push -u origin master

最後に

  • できた
  • よろしくない手順とか設定不足とかあります(気づいてないが絶対・・・)

とりあえずコマンド一覧

構築

ディレクトリを作成する - ルートディレクトリに移動

> cd /
  • ディレクトリ作成
> mkdir User/<user name>/vagrant/<プロジェクト名>
  • 作成したディレクトリに移動
> cd User/<user name>/vagrant/<プロジェクト名>
  • vagrantBox追加
> vagrant add <Box名> <Boxまでのパス>
  • VagrantFileの作成
> vagrant init <Box名>
> vagrant up
$ sudo git clone <GitHubのプロジェクト(httpsかssh)>
  • composerをインストール
$ sudo curl -sS https://getcomposer.org/installer | php
  • composerを移動
$ sudo mv composer.phar /usr/local/bin/composer
  • composerコマンドでlaravelプロジェクト作成
composer create-project laravel/laravel --prefer-dist <プロジェクト名>

memo

vagrant -v
  • vagrantBoxの確認
vagrant box list

環境構築(の準備)

今回の目的

  • 環境構築する前に必要なものを列挙してみる
  • 自分が使っているもの(またはおすすめのみ)書いてませう

VirtualBox

Vagrant

VagrantBox

  • VagrantBox
    • 今回は大先輩から頂いた神Boxを使わせていただきますorz

Gitアカウント

IDE

ssh接続(windowsの場合)

足りないものは随時更新(予定)