LoginSignup
0
0

More than 3 years have passed since last update.

Mac に Laravel6.X のローカル開発環境構築

Last updated at Posted at 2019-12-07

ブラウザで VM に設置した Laravel6 プロジェクトのトップページを表示するまでの作業ログ
本家が提供してくれてる Homestead なるもので簡単に出来るらしい。

各種インストール

VirtualBox をインストール

Vagrant をインストール

Homestead Vagrant Box のインストール

今回は Homestead も 共有フォルダ(後述) もユーザーの Home に設置する。

$ cd ~
$ vagrant box add laravel/homestead

※ダウンロードに数十分ぐらいかかった

Homestead のインストール

$ git clone https://github.com/laravel/homestead.git ~/Homestead

$ cd ~/Homestead

$ bash init.sh

Homestead の設定ファイルを修正する

$ vi Homestead.yaml

authorizekeys の項目は公開鍵&秘密鍵を記述するだけなので省略

下記の内容で一部書き換え

項目 名称
Mac - VM 間の共有フォルダ名 tukanpo-proj
Laravel プロジェクト名 tukanpo
DB名 tukanpo
folders:
    - map: ~/tukanpo-proj
      to: /home/vagrant/tukanpo-proj

sites:
    - map: tukanpo.test
      to: /home/vagrant/tukanpo-proj/tukanpo/public

databases:
    - tukanpo

mac に共有フォルダ作成

$ mkdir ~/tukanpo-proj
$ chmod 755 ~/tukanpo-proj

Vagrant のインスタンスを起動する

$ vagrant up

Vagrant へ接続

$ vagrant ssh
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-72-generic x86_64)

Thanks for using
 _                               _                 _
| |                             | |               | |
| |__   ___  _ __ ___   ___  ___| |_ ___  __ _  __| |
| '_ \ / _ \| '_ ` _ \ / _ \/ __| __/ _ \/ _` |/ _` |
| | | | (_) | | | | | |  __/\__ \ ||  __/ (_| | (_| |
|_| |_|\___/|_| |_| |_|\___||___/\__\___|\__,_|\__,_|

* Homestead v10.0.0 released
* Settler v9.1.0 released

0 packages can be updated.
0 updates are security updates.


vagrant@homestead:~$

Laravel プロジェクト生成

vagrant@homestead:~$ cd tukanpo-proj
vagrant@homestead:~/tukanpo-proj$ composer create-project --prefer-dist laravel/laravel tukanpo

※ Laravel のバージョン指定するには別途コマンドに追記が必要

仮想サーバーのホスト名解決

mac の hosts に下記を追加

$ sudo vi /etc/hosts
192.168.10.10   tukanpo.test

確認

接続できないとき

自分は Homestead.yamlfolderssites の設定ミスでハマった。

Homestead.yamlsites プロパティを修正する場合は下記のコマンドを実行しないと更新されないので注意。

$ vagrant reload --provision

バージョン確認方法

Laravel

vagrant@homestead:~/tukanpo-proj/tukanpo$ php artisan -V
Laravel Framework 6.6.2

Homestead

$ vi ~/Homestead/bin/homestead

この行

$app = new Symfony\Component\Console\Application('Laravel Homestead', '10.0.1');

ここで一旦保存

リモートリポジトリは事前に作っておく

$ cd ~/tukanpo-proj
$ git init
$ git add .
$ git commit
$ git remote add origin git@github.com:tukanpo/tukanpo-proj.git
$ git fetch
$ git merge --allow-unrelated-histories origin/master

参考

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