vagrantを使った仮想環境で新規laravelプロジェクトを作成、Gitの設定までしてみた(Windows)
はじめに
やりたいこと
- 仮想環境の構築
- laravelを使った新規プロジェクト作成
- GitHubでプロジェクトを管理
実行環境
- Windows8.1
事前準備
- VirtualBox
- Vagrant
- VagrantBox
- CentOS
- Nginx
- TeraTerm
仮想環境の構築
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
TeraTermでssh接続
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」をクリック
ゲスト側で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
最後に
- できた
- よろしくない手順とか設定不足とかあります(気づいてないが絶対・・・)