kevnk

Menu

Quick Steps to Setup Laravel 5.0 on Yosemite


First-time Laravel 5.0 Setup

If you want a video to get you through most of these steps, watch the Laracast.

1. Setup Composer

I already had composer installed, but I need to update it. To update composer, run this command:

1
$ composer self-update

Also, make sure composer is in your

1
PATH
by adding this line to your
1
~/.bash_profile

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

2. Install Vagrant

Download vagrant. After installing, you should be able to run

1
vagrant
in Terminal and see the command help.

3. Install Virtualbox

Download VirtualBox.

4. Install Homestead

This command takes maybe 5-10 minutes.

1
2
3
$ vagrant box add laravel/homestead
$ composer global require "laravel/homestead=~2.0"
$ homestead init

5. Setup up SSH keys

If you haven’t already setup your SSH keys, run:

1
$ ssh-keygen -t rsa -C "your_email@example.com"

6. Configure Homestead

1
$ homestead edit
  1. Set
    1
    
    folders: map:
    
    to the directory where all your projects are
  2. Set
    1
    
    folders: to:
    
    to
    1
    
    /home/vagrant/
    
    + the name of the last directory in
    1
    
    map:
    
    above

NOTE: these two folders will automatically always be in sync.

Setup A New Laravel 5.0 Project

Server Setup

1. Configure Project in Homestead

1
$ homestead edit
  1. Set
    1
    
    sites: map:
    
    to
    1
    
    myproject.app
    
  2. Set
    1
    
    sites: to:
    
    to
    1
    
    /home/vagrant/path/to/myproject/public
    
  3. Copy the
    1
    
    ip:
    
    up top on this file for the next step

2. Add Project Url To Hosts File

Add this line to your

1
/etc/hosts
file, replacing
1
YOUR_IP
with the IP you copied in the previous step.

1
YOUR_IP myproject.app

3. Run Site Locally

After this command and you should be able to access

1
http://myproject.app
in your browser.

1
$ homestead up

Database Access

1. Add Project DB Credentials to Homestead

1
$ homestead edit
  1. Add to
    1
    
    databases:
    
    your project’s database:
    1
    
    - myproject
    
  2. Copy the
    1
    
    ip:
    
    up top on this file for the Sequel Pro step

2. Configure Database Credentials

Open

1
myproject/.env
file and set the following:

1
2
3
4
DB_HOST=127.0.0.1
DB_DATABASE=myproject
DB_USERNAME=homestead
DB_PASSWORD=secret

3. Access Database Via Sequel Pro

Open Sequel Pro and setup a new connection, replacing

1
YOUR_IP
with the IP you copied from step 1:

1
2
3
4
5
Name: My Project
Host: YOUR_IP
Username: homestead
Password: secret
Database: myproject

4. Access Database through Terminal

1
2
3
4
$ homestead ssh
$ cd path/to/myproject
$ mysql -uhomestead -p
mysql> show databases;

Laravel 5.0 Project Migration and Seeding

1. Add UserTableSeeder

Add

1
UserTableSeeder.php
to
1
myproject/databases/seeds/
.

NOTE: In order to use the

1
User
model, I had to add
1
use App\User;
to the top of the file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\User;

class UserTableSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        DB::table('users')->delete();

        User::create([
            'name' => 'Your Name',
            'email' => 'your@email.com',
            'password' => 'your_password'
        ]);
    }

}

2. Edit DatabaseSeeder

Uncomment the following in in

1
myproject/databases/seeds/DatabaseSeeder.php
.

1
$this->call('UserTableSeeder');

3. Run Migration and Seeder

1
2
3
$ homestead ssh
$ cd path/to/myproject
$ php artisan migrate:refresh --seed

If that doesn’t work, run

1
composer dump-autoload
and try again.

4. Check in DB for tables and values

Yeah… do that ^

Have Questions or Feedback?

Feel free to leave a comment below or tweet me @kevinkirchner.

Go Read Some Documentation

This should get you up and running. If there’s more you need to figure out, read through the laravel docs (http://laravel.com/) and check out laracasts at (https://laracasts.com)

comments powered by Disqus