20200623のlaravelに関する記事は2件です。

Laravel環境構築時のエラー解決 Mac

エラー内容

$ composer global require laravel/installer

Changed current directory to /Users/ooshiroippei/.composer
Using version ^3.1 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for laravel/installer ^3.1 -> satisfiable by laravel/installer[v3.1.0].
    - laravel/installer v3.1.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.


Installation failed, deleting ./composer.json.

ext-zipが必要

重要なエラー箇所を和訳すると、
「laravel/installer v3.1.0にはext-zipが必要です。リクエストされたPHP拡張zipがシステムにありません」と書かれている。

原因

Macに最初から入っているPHPにはzipのサポート機能がないためエラーが起こっていた。

解決策

これは改めてPHPを入れ直すことで解決できる。

①MacにPHPを再インストールするには「Homebrew」を使う。
こちらを参考。
https://awesome-linus.com/2019/08/17/mac-homebrew-install/

②PHPをインストールする

//HomeBrewのバージョン確認まで終わったらインストール
$ brew install php

//zipがサポートされているか確認
$ php --ri zip

//Laravelインストール
$composer global require laravel/installer

各エラー対策

Extension 'zip' not present.とエラーが出た場合

$ brew link php

brew link phpでエラー

Linking /usr/local/Cellar/php/7.4.7...
Error: Could not symlink sbin/php-fpm
/usr/local/sbin is not writable.

$brew doctor

Warning: The following directories do not exist:
/usr/local/Frameworks
/usr/local/sbin

You should create these directories and change their ownership to your account.
  sudo mkdir -p /usr/local/Frameworks /usr/local/sbin //実行
  sudo chown -R $(whoami) /usr/local/Frameworks /usr/local/sbin //実行

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  php

Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
  echo 'export PATH="/usr/local/bin:$PATH"' >> /Users/user/.bash_profile 
  rake
  bundle
  tidy
  sqlite3
  bundler
  rails

//各エラー項目に出ているコマンドを実行していく。

$sudo mkdir -p /usr/local/Frameworks /usr/local/sbin
$sudo chown -R $(whoami) /usr/local/Frameworks /usr/local/sbin
$echo 'export PATH="/usr/local/sbin:$PATH"' >> /Users/user/.bash_profile
//パスを通したあとは必ずsourceで際読み込み
$source ~/.bash_profile

//バージョンを確認
$php -v

//zipを確認
$ php --ri zip

zip

Zip => enabled
Zip version => 1.15.6
Libzip headers version => 1.7.0
Libzip library version => 1.7.1

//Laravelインストール
$composer global require laravel/installer
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

laravelを勉強してて詰まったこと

目的

この記事の目的は、Laravel開発の備忘録を作成することです。主に、うまくいかなかったことを書きます。自分のような初学者の助けになればいいなと思います。

Databaseのmigrateが上手くいかない

php artisan migrateコマンドを入力すると以下のエラーが出力されました。
migrate.png

デフォルトで設定されている「laravel」なんていう名前のDatabeseは無いよって言われているみたいです。

解決策

composerでlaravel開発のためのディレクトリを作成したときに、「.env」っていう名前のファイルができていますよね。migrate2.png

「.env」ファイルのDatabaseの設定を編集します。
migrate23png.png

12行目にHomestead.yamlファイルに自分の使いたいDatabseの名前を書いて、14行目はパスワードを書きます。デフォルトでは何も書かれていいないです。
Databaseのパスワードはデフォルトでは「secret」に設定されていると思います。(この記事を書く前にいろいろいじってしまっているのでもしかしたら違うかも...)

解決!

こんな画面がでれば解決です!
migrate3png.png

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む