はじめに
簡単にLaravelの環境構築ができる手順を残します。
環境
-
Mac
-
MAMPとComposer(v2.2.4)はインストール済み
-
PHP8.0以上(Laravel9を使用するため)
-
Laravel9をインストールする
-
Laravelの初期設定
- タイムゾーンの設定
- デバックバーのインストール
- データーベースの設定
手順
Laravelをインストールしたいファイルへ移動する
# 移動する
$ cd /Applications/MAMP/htdocs
# ファイルを作成
$ mkdir laravel
# 移動する
$ cd laravel
- バージョンを指定して、Laravelをインストールする
$ composer create-project laravel/laravel プロジェクト名 --prefer-dist "9.*"
$ php artisan serve
タイムゾーンの設定
config/app.php
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'Asia/Tokyo',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => 'ja',
(略)
デバックバーのインストール
- 下記のコマンドでインストールします。
$ composer require barryvdh/laravel-debugbar:^3.7
※本番サイトようで、デバックバーを非表示にする方法
- 下記の
vender/.env
へ移動し、変更
vender/.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=xxxxxxxxx
# trueからfalseへ変更
APP_DEBUG=false
APP_URL=http://localhost
データーベースの設定
-
作成した情報を
vender/.env
へ追記する
vender/.env
DB_CONNECTION=mysql
DB_HOST=xxxxx
DB_PORT=3306
DB_DATABASE=作成したデーターベース名
DB_USERNAME=作成したユーザー名
DB_PASSWORD=作成したパスワード
- マイグレーションを実行する
$ php artisan migrate
まとめ
MAMPを使えば簡単にLaravelの環境を整えることができるので、サクッと環境は作って早くLaravelの勉強をしたい人は参考にしてもらえれば幸いです。