LoginSignup
13
4

More than 5 years have passed since last update.

凄い馬鹿みたいな事で環境構築に躓いた話~戒め~

Last updated at Posted at 2018-12-07

はじめに

最近、新たにVirtualBoxとvagrantで環境構築を行う機会があったのですが
かなり馬鹿みたいな事で半日ほど時間を使ってしまったので、反省とメモを兼ねて記述しておこうと思います。
そのため、内容の大半は無駄に試行錯誤した内容になりますので、大体は役に立ちませんので、ご了承ください。

作業内容

1:順調だった頃

  • VirtualBoxとvagrantのバージョンを確認
  • homesteadをダウンロード
  • Homestead.yamlの編集

2:怪しくなってきた頃

  • vagrantの起動!
  • プロジェクトの設定
  • composer install実行

3:エラーとの出会い

  • php artisan key:generateでキーの生成……ん?
PHP Warning:  require(/home/vagrant/code/web/vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/code/web/artisan on line 18

Warning: require(/home/vagrant/code/web/vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/code/web/artisan on line 18
PHP Fatal error:  require(): Failed opening required '/home/vagrant/code/web/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/vagrant/code/web/artisan on line 18

Fatal error: require(): Failed opening required '/home/vagrant/code/web/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/vagrant/code/web/artisan on line 18
vagrant@homestead:~/code/web$ sudo php artisan key:generate
PHP Warning:  require(/home/vagrant/code/web/vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/code/web/artisan on line 18

Warning: require(/home/vagrant/code/web/vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/code/web/artisan on line 18
PHP Fatal error:  require(): Failed opening required '/home/vagrant/code/web/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/vagrant/code/web/artisan on line 18

Fatal error: require(): Failed opening required '/home/vagrant/code/web/vendor/autoload.php' (include_path='.:/usr/share/php') in /home/vagrant/code/web/artisan on line 18

おおう!?エラー発生!?
という訳で調査してみる。

4:調査開始

とりあえず出たエラーそのままで検索してみる。
するとファイルが無いので、composer を install すれば良いらしい

あれ?一回すでに composer install 実行したはずなんだけど…?
漏れがあったのかな?と思いつつもう一度実行。

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating optimized autoload files

  [RuntimeException]
  Could not scan for classes inside "database/seeds" which does not appear to be a file nor a folder

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...

ん? [RuntimeException]?
気付かなかったけど composer の install で失敗していたらしい。
RuntimeException って事は無理矢理でも時間を延ばせばいいのでは?と以下のコマンドを実行してもう一度試してみる。

$ export COMPOSER_PROCESS_TIMEOUT=1200
$ composer install

ちょっとワクワクしながら待ってみるも先ほどと同じく [RuntimeException] …
もう一度エラー文言見てみると、"database/seeds"のフォルダがスキャンできないからRuntimeExceptionが発生しているらしい。
試しに指定された"database/seeds"フォルダを作成して、再度試してみることに

$ mkdir database/seeds
$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating optimized autoload files

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: barryvdh/laravel-ide-helper
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Package manifest generated successfully.
> @php artisan ide-helper:generate

In TransportManager.php line 80:

  Class 'Aws\Ses\SesClient' not found

Script @php artisan ide-helper:generate handling the post-install-cmd event returned with error code 1

前と違う反応が返ってきた!
気になる文章が幾つかあるけど一旦試で先に進めてみる。

$ php artisan key:generate
Application key [base64:hogehoge+BivhogeSXJHi6kZWChogeQRfySMb3g=] set successfully.

(゚∀゚)キタコレ!!
前はエラーで返ってきたものが通った!
そのままの調子でmigrationも通してしまえ!

$ php artisan migrate
In Connection.php line 664:

  SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO) (SQL: select * from information_schema.tables where
   table_schema =  and table_name = migrations)

In PDOConnection.php line 50:
  SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

In PDOConnection.php line 46:
  SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

あれ?でも Access denied で怒られているならDBのユーザー権限を見直せば問題ないはず!
DBの中に入ってユーザーの権限を確認してみる。

mysql> SHOW GRANTS for 'homestead'@'%';
+------------------------------------------------------------------+
| Grants for homestead@%                                           |
+------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'homestead'@'%' WITH GRANT OPTION |
+------------------------------------------------------------------+
1 row in set (0.00 sec)

あれ、全権限持ってる…?
指定しているユーザーが間違っているのかと .envファイルを確認しても特に問題はなさそう。

5:原因発覚

暫く悩んだ後、実際の migrationファイルも確認しておこうと思いソースを確認してみると、何故かlaravelの初期ファイルしか存在しない。
あれ…と暫く悩んでからとんでもない事に気が付きました。

自分、今… 何もマージされていないブランチにいる…
そりゃあ composerが上手く動作しないし、migrationも実行できない訳です。設定や、ファイルが存在しないので…

6:それから

他にも hostの設定が漏れていたり、APP_KEYの設定がズレていたりしたけども特に問題なく環境構築が終了。
悩んだ大半の原因がただ Gitのリモートブランチを確認していなかったからという馬鹿みたいな躓きの話です。

皆様も、リモートブランチには十分気を付けて作業しましょう

こんな事で躓く人自分だけかもしれませんが…

13
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
4