Created
May 11, 2015 19:38
-
-
Save ryanorsinger/580b8949c477c8f4767e to your computer and use it in GitHub Desktop.
First Steps after installing Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As soon as you create a new Laravel project, it will default itself to be in production mode (so that stack traces don't show up) and still needs you to put in $ENV placeholders for the database login credentials. Since we NEVER commit passwords or API keys to github, we need to use $ENV as a placeholder and then create .env.local.php in order to store the actual values. Your .env.local.php file is automatically ignored by git, so this is where you put your credentials. | |
In bootstrap/start.php on line 27, change to the following: | |
$env = $app->detectEnvironment(function() { | |
return isset($_SERVER['LARAVEL_ENV']) ? $_SERVER['LARAVEL_ENV'] : 'production'; | |
}); | |
Delete app/config/local/database.php file. | |
Edit app/config/database.php in the following way: | |
replace these lines: | |
'host' => 'localhost', | |
'database' => 'forge', | |
'username' => 'forge', | |
'password' => '', | |
with these lines: | |
'host' => $_ENV['DB_HOST'], | |
'database' => $_ENV['DB_NAME'], | |
'username' => $_ENV['DB_USER'], | |
'password' => $_ENV['DB_PASS'], | |
Create a file named env-template.php in your blog.dev/ folder or project.dev folder. Add the $_ENV['key_names'] that you'll use in here. DO NOT PROVIDE ANY VALUES IN THIS FILE. This is a template file that's just to keep a nice list of your ENV variables. The values in this file will always be blank strings. | |
<?php | |
return array( | |
'DB_HOST' => '', | |
'DB_NAME' => '', | |
'DB_USER' => '', | |
'DB_PASS' => '', | |
); | |
Create a file named .env.local.php immediatley in your blog.dev/ folder or project.dev/ folder | |
`<?php | |
return array( | |
'DB_HOST' => '127.0.0.1', | |
'DB_NAME' => 'your_existing_database_name', | |
'DB_USER' => 'your_db_username', | |
'DB_PASS' => 'your_lengthy_password', | |
);` | |
Remember that your database, db user, and db password need to already exist or be created before you can use them here. | |
To do this, go to the ~/vagrant-lamp on your Mac, | |
Run ansible-playbook ansible/mysql-user-db.yml -l vagrant -e "db_name=<your database name>" | |
Also: | |
Add a constructor to your BaseController that will check the CSRF token for POST, PUT, and DELETE requests. | |
public function __construct() | |
{ | |
// require csrf token for all post, delete, and put actions | |
$this->beforeFilter('csrf', array('on' => array('post', 'delete', 'put'))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment