0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Posted at

エラー内容

$ 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
0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?