Help us understand the problem. What is going on with this article?

【Mac OS 10.15.2】Laravel入れようとしたら詰まった話

初めてMacにLaravel入れようとしたら普通に詰まったので共有します。

経緯

・Homebrewにて、MacにPHPをインストールした。
・ComposerをMacに入れてパスを通した
・以下のコマンドを入力したところで問題発生

composer global require laravel/installer

問題

エラーコード

まずはこんなエラーコードが出ました。

mbp:~ 【ユーザーネーム】$ composer global require laravel/installer
Changed current directory to /Users/【ユーザーネーム】/.composer

Using version ^3.0 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
    - laravel/installer v3.0.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - laravel/installer v3.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - Installation request for laravel/installer ^3.0 -> satisfiable by laravel/installer[v3.0.0, v3.0.1].

Laravelをインストールするときに、どこのPHPを見ているのか確認

コマンド:which php
結果:/usr/bin/php

ここからわかること

・パスがMac標準PHPのものになっているらしい。
・どうやら標準PHPには「zip」らしきものが無いっぽい。
・/usr/bin/phpではなく、/usr/local/opt/phpを見て欲しいのに。

HomebrewでPHPをインストール出来ているかを確認

コマンド:brew install php@7.3
結果:
Warning: php@7.3 7.3.14 is already installed and up-to-date
To reinstall 7.3.14, run `brew reinstall php@7.3`

ここからわかること

・もうすでにhomebrewでのPHPインストールは終わっている。

PHPを念のため再インストール

コマンド:brew reinstall php@7.3
【結果】
==> Reinstalling php@7.3 
==> Downloading https://homebrew.bintray.com/bottles/php@7.3-7.3.14.catalina.bottle.tar.gz
Already downloaded: /Users/【ユーザーネーム】/Library/Caches/Homebrew/downloads/42f5213d06a0456cf231786c8bf93b8fe340b153e0467babad9e5a0ca2935832--php@7.3-7.3.14.catalina.bottle.tar.gz
==> Pouring php@7.3-7.3.14.catalina.bottle.tar.gz
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set php_ini /usr/local/etc/php/7.3/php.ini syst
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set php_dir /usr/local/share/pear@7.3 system
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set doc_dir /usr/local/share/pear@7.3/doc syste
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set ext_dir /usr/local/lib/php/pecl/20180731 sy
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set bin_dir /usr/local/opt/php@7.3/bin system
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set data_dir /usr/local/share/pear@7.3/data sys
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set cfg_dir /usr/local/share/pear@7.3/cfg syste
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set www_dir /usr/local/share/pear@7.3/htdocs sy
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set man_dir /usr/local/share/man system
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set test_dir /usr/local/share/pear@7.3/test sys
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear config-set php_bin /usr/local/opt/php@7.3/bin/php syst
==> /usr/local/Cellar/php@7.3/7.3.14/bin/pear update-channels
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php@7.3/lib/httpd/modules/libphp7.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.3/

php@7.3 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@7.3 first in your PATH run:
  echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.bash_profile

For compilers to find php@7.3 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@7.3/lib"
  export CPPFLAGS="-I/usr/local/opt/php@7.3/include"


To have launchd start php@7.3 now and restart at login:
  brew services start php@7.3
Or, if you don't want/need a background service you can just run:
  php-fpm
==> Summary
🍺  /usr/local/Cellar/php@7.3/7.3.14: 521 files, 77MB

ここからわかること

・インストールは完了している。
よく見ると・・・。

php@7.3 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@7.3 first in your PATH run:
  echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.bash_profile

For compilers to find php@7.3 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@7.3/lib"
  export CPPFLAGS="-I/usr/local/opt/php@7.3/include"

解決策

※このコマンドをこのまま入力しても良いですが、記事が古くなっている可能性があるので上記コマンドを入力しつつ自分の環境で何が起こっているのかを確認してください。

  echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.bash_profile

  export LDFLAGS="-L/usr/local/opt/php@7.3/lib"
  export CPPFLAGS="-I/usr/local/opt/php@7.3/include"

この4つのコマンドを記入後、

$ source ~/.bash_profile

このコマンドを入力したら、無事Laravelインストールが出来るようになりました。
めでたし!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした