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:
$ composer self-update
Also, make sure composer is in your PATH
by adding this line to your ~/.bash_profile
export PATH=~/.composer/vendor/bin:$PATH
2. Install Vagrant
Download vagrant. After installing, you should be able to run vagrant
in Terminal and see the command help.
3. Install Virtualbox
Download VirtualBox.
4. Install Homestead
This command takes maybe 5-10 minutes.
$ 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:
$ ssh-keygen -t rsa -C "your_email@example.com"
6. Configure Homestead
$ homestead edit
- Set
folders: map:
to the directory where all your projects are - Set
folders: to:
to/home/vagrant/
+ the name of the last directory inmap:
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
$ homestead edit
- Set
sites: map:
tomyproject.app
- Set
sites: to:
to/home/vagrant/path/to/myproject/public
- Copy the
ip:
up top on this file for the next step
2. Add Project Url To Hosts File
Add this line to your /etc/hosts
file, replacing YOUR_IP
with the IP you copied in the previous step.
YOUR_IP myproject.app
3. Run Site Locally
After this command and you should be able to access http://myproject.app
in your browser.
$ homestead up
Database Access
1. Add Project DB Credentials to Homestead
$ homestead edit
- Add to
databases:
your project’s database:- myproject
- Copy the
ip:
up top on this file for the Sequel Pro step
2. Configure Database Credentials
Open myproject/.env
file and set the following:
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 YOUR_IP
with the IP you copied from step 1:
Name: My Project
Host: YOUR_IP
Username: homestead
Password: secret
Database: myproject
4. Access Database through Terminal
$ homestead ssh
$ cd path/to/myproject
$ mysql -uhomestead -p
mysql> show databases;
Laravel 5.0 Project Migration and Seeding
1. Add UserTableSeeder
Add UserTableSeeder.php
to myproject/databases/seeds/
.
NOTE: In order to use the User
model, I had to add use App\User;
to the top of the file.
<?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 myproject/databases/seeds/DatabaseSeeder.php
.
$this->call('UserTableSeeder');
3. Run Migration and Seeder
$ homestead ssh
$ cd path/to/myproject
$ php artisan migrate:refresh --seed
If that doesn’t work, run 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)