0
0

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.

MacにLaravelインストールしたメモ

Posted at

この度初めてMacを購入してLaravelの環境構築を行ったのでメモ。調べながらトライしてなんとか完了。が、2つハマったポイントがありました。

1. システム環境

  ・macOS Catalina10.15.6

   すべてMacのターミナルで作業。
  (ちなみにハマった理由の1つがOSのverとターミナルが関係。)

2. 手順

  Ⅰ.Composerインストール
  以下を実行。

curl -sS https://getcomposer.org/installer | php

つぎにcomposerをどの作業場所からでも呼べるように設定。

mv composer.phar /usr/local/bin/composer

インストール後,以下のコマンドで

composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.10.9 2020-07-16 12:57:00

上記表示されれば正常にインストール完了。

  Ⅱ.Composerを使ってLaravelインストーラーをインストール

  以下を実行。

composer global require "laravel/installer"

※ハマりポイント1
しかし、ここでエラー出てしまいました。どうもmacにはじめからインストールされているPHPではext-zipに対応してませんよ、ということらしい...(Problem1の2段目の部分)

Changed current directory to /Users/ryo3110/.composer
Using version ^3.2 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.2 -> satisfiable by laravel/installer[v3.2.0].
    - laravel/installer v3.2.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.


Installation failed, deleting ./composer.json.

これをPHPをインストールし直すことで対応。MacにはHomebrewというパッケージ管理システムがあるのでこちらを利用する。

以下のコマンドでHomebrewをインストール

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

インストールできたらbrewコマンドでphpをインストールする。普段を使用しているので7.4にした。ここは使い慣れているver.でいいはず。

$ brew install php@7.4

インストールできたら改めてLaravelインストーラーのインストールを試みる。

composer global require "laravel/installer"

無事インストーラーのインストール完了。

Ⅲ.Laravelコマンド使えるようにパスを通す

この時点ではターミナル開いてすぐにLaravelコマンドが使えないのでパスの設定を行う。以下を実行。

echo "export PATH=~/.composer/vendor/bin:$PATH" >> ~/.bash_profile

.bash_profileを読み込み。

source ~/.bash_profile

これでターミナルにlaravelと打てばlaravelコマンドが使える。

※ハマりポイント2
しかしターミナルをと閉じると使えなくなってしまう...どうもパスの設定が保存されていないのではと考えひたすら調べる。。。

どうやらCatalinaから標準シェルがbashからzshに変わっていることで.bash_profileを読み込まないのが原因と判明。(Mac初めて買ったのに、変わってるとかそんなん知らん...)後ほど気づいたのですが、そもそも使用不可のコマンド打ったとき、zsh: command not foundと表示されるのでちゃんと確認しておくべきでした...

ともあれ、原因わかったので再度トライ。従来のbashにも設定できるようだが、Appleがzshに切り替えたということで今後しばらくその方針になることを考えて、zshを使う方針で対応。

ターミナルのホームディレクトリに.zshrcをつくる。(vimで作業)

vim .zshrc

下記を入力し保存する。

export PATH=$PATH:~/.composer/vendor/bin

これでなんとかターミナルを閉じてもすぐにLaravelコマンドが使えるようになった。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?