LoginSignup
0
0

More than 3 years have passed since last update.

Laravelはじめる時のメモ(Mac)

Last updated at Posted at 2019-06-10

MacでLaravelを使う時の備忘録です。

background.png

まず、開発環境に古いものがないかを確認する。

  • PHP >= 7.1.3
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • mbstring PHP Extension
  • tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • BCMath PHP Extension
terminal
$ php -v
→ PHP 7.1.23 (cli) (built: Feb 22 2019 22:19:32) ( NTS )

PHPのバージョンが足りていない気がするので、アップデートする。

terminal
$ brew search php@7
==> Formulae
php@7.1                         php@7.2                         php@7.3

7.1で大丈夫と思うんですが、7.3をインストールします。

$ brew install php@7.3

10分位後にターミナルを再起動する

$ php -v
PHP 7.3.6 (cli) (built: May 31 2019 23:38:25) ( NTS )
terminal
$ openssl version
→ LibreSSL 2.6.5
terminal
$ php -i|grep PDO
→ PDO
terminal
$ php -i|grep mbstring
→ mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
terminal
$ php -i|grep tokenizer
tokenizer
terminal
$ php -i|grep XML
XML Support => active
terminal
$ php -i|grep BCMath
BCMath support => enabled

grepしてもCtypeJSONがないような気がする

terminal
$ php -m

PHP読み込まれているモジュールを調べるには?
■参考リンク:
https://www.php.net/manual/ja/function.extension-loaded.php

ctypejsonがあったのでOK。

■インストール全般の参考リンク
https://readouble.com/laravel/5.5/ja/installation.html
http://kimagureneet.hatenablog.com/entry/2016/08/18/194857

Laravelインストールしてたっけ?

まず、ローカルにLaravelあったかを調べる
ない場合「コマンドが見つかりません」と出ます。

terminal
$ laravel -V
-bash: laravel: command not found

Laravelをインストールしよう。

terminal
$ composer global require "laravel/installer"

「まずcomposerがない?」
まずhomebrewcomposerをインストールする場合はコレです。

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

ホームディレクトリ直下の.bashrcにコレを書いておく。

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

パスを通す

terminal
$ source .bashrc

ココまでやったらFinderで確認してみる。これで何にパスを通したか分かる。
スクリーンショット 2019-06-10 11.54.13.png

もう一度Laravelのバージョンを調べて見る。

terminal
$ laravel -V
Laravel Installer 2.1.0

新しいプロジェクトを作成

新しいプロジェクトを作る

terminal
$ laravel new ○○○○ //←自分の好きな名前をつけて下さい。

ディレクトリを移動する

terminal
$ cd ○○○○

テスト用のサーバーを起動して見る。

terminal
$ php artisan serve --host 0.0.0.0
Laravel development server started: <http://0.0.0.0:8000>

ブラウザで「http://0.0.0.0:8000」にアクセスすると、何かが見える。
スクリーンショット 2019-06-10 12.05.01.png

ちなみにサーブを止めるにはCtrl+Cを同時押しすると止まる。

タイムゾーンを変更する

作られたプロジェクトの中にあるconfig/app.phpを開きます。
スクリーンショット 2019-06-10 12.16.25.png

開くと色々説明が書いてあるんですが、読まずにtimezoneで検索してUTCAsia/Tokyoに書き換える。
localeの箇所もenになってるのでjaに書き換える。
スクリーンショット 2019-06-10 12.15.49.png

権限(パーミッション)を書き換える

storagebootstrap/cacheこの2つは読み書きの権限が必要だそうです。
スクリーンショット 2019-06-10 12.26.57.png
権限を書き換えます。

terminal
$ chmod 777 storage
$ chmod 777 ./bootstrap/cache/

アプリケーションキーがある?調べる

自動で作られると思いますが。プロジェクトの中に.envというファイルがある。
そこにAPP_KEYというのがあるか確認しておく。
スクリーンショット 2019-06-10 12.34.13.png

laravelインストーラーのバージョンを上げる

terminal
$ composer global update laravel/installer

データベースとの接続を確認する

terminal
$ php artisan migrate

とうぜん接続エラー。データベースを用意する。

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