Laravel 4 Install & Setup

17 Sep

I’ve documented the process I follow when setting up a new Laravel 4 application. This is for my reference, but you might find it helpful as well. Feel free to leave comments if you do something different or if you have any suggestions. Don’t forget to share this with anyone who might benefit from it. Thanks!

First thing you need is the laravel framework in a project directory. You can create the directory and install the framework with a single command using composer:

 ▶ composer create-project laravel/laravel MyProject

Next you should set the permissions for app/storage to allow the user the webserver is running as to write to that directory:

 ▶ chmod -R ug+w app/storage
NOTE: This assumes your entire project folder is in the webserver’s group

Next initialize your new project directory as a git repo. This way any changes from here out can be reverted back to a fresh install of Laravel.

 ▶ git init
 ▶ git add --all
 ▶ git commit -m "Initial commit."

OPTIONAL: Personally, I like to use git flow as my branch management so I initialize that as well here:

 ▶ git flow init

Update your .gitignore file to look like the following:

 .idea
 /bootstrap/compiled.php
 /vendor
 /app/storage
 composer.phar
 .env.*.php
 .env.php
NOTE: The .idea file is created by PHPStorm and is only needed if you use that IDE.

Laravel will be running in the production environment by default. You need to setup your local environment. In bootstrap/start.php under the Detect The Application Environment section add whatever environment(s) you need. For example:

'local' => array('freshbookpro', 'http://*.dev', 'http://*.local', '*.local*', '127.0.0.1', 'localhost*');

Confirm your setup by running the following command from the project root:

 ▶ php artisan env
 Current application environment: local

Setup a database to use for your application

Create an .env.local.php file and add your credentials for the local database. It should look something like this:


Add a variable to hold the URL of the local environment:

'HOST_URL' => 'http://localhost:8000'
NOTE: This will allow us to use this as the variable for all assets to be loaded as $_ENV['HOST_URL'].

Update the app/config/local/database.php with the correct mysql information to use the $_ENV vars setup in .env.local.php. It should look like this:

'mysql' => array(
 'driver' => 'mysql',
 'host' => $_ENV['DB_HOST'],
 'database' => $_ENV['DB_DATABASE'],
 'username' => $_ENV['DB_USER'],
 'password' => $_ENV['DB_PASS'],
 'charset' => 'utf8',
 'collation' => 'utf8_unicode_ci',
 'prefix' => '',
),

Now for some sugar in your app and dev environment

Add laracast/flash messages for your app. In the composer.json file add:

"require": {
    "laracasts/flash": "~1.0"
}

Add the Service Provider to app/config/app.php:

'Laracasts\Flash\FlashServiceProvider'

Add xethron/migrations-generator for your dev environment. In the composer.json file add:

 "require-dev": {
    "xethron/migrations-generator": "dev-master"
 }

Add the Service Provider to app/config/local/app.php:

'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider'

Add way/generators for your dev environment. In the composer.json file add:

 "require-dev": {
     "way/generators": "2.*"
 }

Add Service Provider to config/local/app.php:

'Way\Generators\GeneratorsServiceProvider'

Don't forget to composer update!

Now you should be all good to go!

Leave a Reply

Your email address will not be published. Required fields are marked *