カテゴリー
サインイン 新規登録

間違いや改善の指摘

内容の技術的な誤り・誤字脱字やミスのご報告・解説やトピックの追記/改善のご要望は教材をさらに良くしていく上でとても貴重なご意見になります。

少しでも気になった点があれば、ご遠慮なく投稿いただけると幸いです🙏

実際には誤りではなく勘違いであっても、ご報告いただけることで教材のブラッシュアップにつながります。

質問ポリシー①

教材受講者みなさんのスムーズな問題解決のために、心がけていただきたいことがあります。

教材の内容に関する質問を投稿しましょう

教材の内容に関係のない質問や教材とは異なる環境・バージョンで進めている場合のエラーなど、教材に関係しない質問は推奨していないため回答できない場合がございます。

その場合、teratailなどの外部サイトを利用して質問することをおすすめします。教材の誤字脱字や追記・改善の要望は「文章の間違いや改善点の指摘」からお願いします。

0-2

Laravelの環境構築(Mac)

0-2 : Laravelの環境構築(Mac)

Homebrewのインストール

HemobrewはmacOS用のパッケージマネージャーです。Homebrewを使うとターミナル上でオープンソースソフトウェアを管理できます。

Xcodeのインストール

Homebrew の公式サイトに書かれているように、Homebrew をインストールするためには Xcode の Command Line Tools が必要です。

ターミナルで以下のコマンドを実行してください。

Copied!
$ xcode-select --install

正しくインストールされている場合は以下のコマンドでバージョン確認ができます。

Copied!
$ xcode-select -v xcode-select version 2354.

これでXcodeのインストールは完了です。

Homebrewのインストール

Xcodeのバージョンが表示されてインストールの確認ができたら、Homebrewをインストールできます。

ターミナルで以下のコマンドを実行してください。
(途中でEnterの入力/インストールユーザのOSパスワードの入力を求められます)

Copied!
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

以下のコマンドを実行して「Your system is ready to brew.」と表示されれば正しくインストールされています。

Copied!
$ brew doctor Your system is ready to brew.

これでHomebresのインストールは完了です。

PHP7.3のインストール

次にPHPのインストールを行います。

Laravelを使うにはPHPのバージョンは7以上である必要があるので、brew search php@7でPHP7系を検索します。

Copied!
$ brew search php@7

以下のメッセージが表示されます。

Copied!
==> Formulae php@7.1 php@7.2 php@7.3 ✔

そうしたらbrew install php@7.3を実行して、PHP7.3をインストールします。

Copied!
$ brew install php@7.3

brew install php@7.3実行時に依存関連のモジュールであるPythonインストール時にerrorがでる場合があります。

Copied!
An unexpected error occurred during the `brew link` step The formula built, but is not symlinked into /usr/local Permission denied @ dir_s_mkdir - /usr/local/Frameworks

/usr/local/Frameworksの権限がないとのことです。
指示通りディレクトリを作成して、権限を付与します。

Copied!
$ sudo mkdir /usr/local/Frameworks $ sudo chown $(whoami):admin /usr/local/Frameworks $ brew link python

もう一度brew install php@7.3brew install php@7.3を実行します。

Copied!
$ brew search php@7 $ brew install php@7.3

今度は以下のエラーが出る場合があります。

Copied!
Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink sbin/php-fpm /usr/local/sbin is not writable. You can try again using: brew link php

指示通りにbrew link phpを実行します。

Copied!
$ brew link php

Pythonのインストールと同様のエラーが発生する場合があります。

Copied!
An unexpected error occurred during the `brew link` step The formula built, but is not symlinked into /usr/local Permission denied @ dir_s_mkdir - /usr/local/sbin

Pythonインストール時と同じようにディレクトリに権限を付与します。

Copied!
$ sudo mkdir /usr/local/sbin $ sudo chown $(whoami):admin /usr/local/sbin $ brew link php

問題なくインストールできれば、以下のメッセージが出できます。

Copied!
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

指示通りに以下のコマンドを実行し、phpを再起動します。

Copied!
$ 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 $ brew services start php

最後にターミナルを再起動して、php -vを実行してください。

Copied!
$ php -v
Copied!
PHP 7.3.7 (cli) (built: Jul 5 2019 12:44:05) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.7, Copyright (c) 1999-2018, by Zend Technologies

が出れば成功です。

※Laravel6.0ではPHP7.2以上が必須とされています。

念の為 phpinfoを確認するために以下のコマンドを実行してください。

Copied!
$ touch index.php $ echo "<?php phpinfo(); ?>" >> index.php $ php -S localhost:8000

localhost:8000にアクセスし、以下の画像の通り表示されれば成功です。

スクリーンショット 2019-07-14 15 59 42

Composerのインストール

PHPのパッケージ管理ツールComposerインストールしていきます。

まずはbrew search composerでComposerを検索します。

Copied!
$ brew search composer

以下のコンソールが表示されます。

Copied!
==> Formulae composer ✔

そうしたらばbrew install composerを実行して、Composerをインストールします。

Copied!
$ brew install composer

エラーなどがでなければ成功です。

composer -vを実行して成功したか確認します。

Copied!
$ composer -v

以下のようなコンソールが出れば成功です。

Copied!
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.8.6 2019-06-11 15:03:05 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information --no-plugins Whether to disable plugins. -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: about Shows the short information about Composer. archive Creates an archive of this composer package. browse Opens the package's repository URL or homepage in your browser. check-platform-reqs Check that platform requirements are satisfied. clear-cache Clears composer's internal package cache. clearcache Clears composer's internal package cache. config Sets config options. create-project Creates new project from a package into given directory. depends Shows which packages cause the given package to be installed. diagnose Diagnoses the system to identify common errors. dump-autoload Dumps the autoloader. dumpautoload Dumps the autoloader. exec Executes a vendored binary/script. global Allows running commands in the global composer dir ($COMPOSER_HOME). help Displays help for a command home Opens the package's repository URL or homepage in your browser. i Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json. info Shows information about packages. init Creates a basic composer.json file in current directory. install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json. licenses Shows information about licenses of dependencies. list Lists commands outdated Shows a list of installed packages that have updates available, including their latest version. prohibits Shows which packages prevent the given package from being installed. remove Removes a package from the require or require-dev. require Adds required packages to your composer.json and installs them. run-script Runs the scripts defined in composer.json. search Searches for packages. self-update Updates composer.phar to the latest version. selfupdate Updates composer.phar to the latest version. show Shows information about packages. status Shows a list of locally modified packages, for packages installed from source. suggests Shows package suggestions. u Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file. update Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file. upgrade Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file. validate Validates a composer.json and composer.lock. why Shows which packages cause the given package to be installed. why-not Shows which packages prevent the given package from being installed.

以上で環境構築は完了です。

お疲れ様でした。