5
votes

I was wondering if someone could help out.

I have run through the environment setup for Laravel 4 and it doesnt seem to be working.

In my MAMP setup, i created protected.dev host

In my Bootstrap->start.php i have my local url like so

$env = $app->detectEnvironment(array(
    'local' => array('protected.dev')
));

I have created a 'local' directory in the app->config directory, copied over the standard database.php file and then modified the database.php file inside the 'local' directory.

When i try and show the site, i get the

Access denied for user 'root'@'localhost'

which is in the standard config->database.php file.

It doesnt seem to be detecting its a local environment for some reason.

Any help would be greatly appreciated.

Cheers,

4

4 Answers

16
votes

In laravel 4, the enviroments are set by the machine name, not by the web server url.

To determine your hostname use the hostname terminal command.

Type hostname in your terminal (this works on linux and mac) and cut and paste the result in your start.php file in the local variable and it should work fine.

example:

angoru@angel-mountain:~$ hostname

angel-mountain

my start.php

$env = $app->detectEnvironment(array(
  'local' => array('angel-mountain'), // Change this to your local machine hostname.
  'staging' => array('your-staging-machine-name'),
  'production' => array('your-production-machine-name'),
));

For more explanation: Environment Configuration

3
votes

Laravel 4 doesn't rely on virtual host to detect the working environment any more. It now uses the machine's hostname to do it. So you need to change protected.dev to your machine's hostname. On Linux, you can find out your machine's hostname by running the following command in the terminal:

hostname

More on this http://laravel.com/docs/configuration#environment-configuration

1
votes

In environments with several developers each one may add its hostname to the 'local' array in start.php:

$env = $app->detectEnvironment(array(
  'local' => array('user1-hostname','user2-hostname'), // Developers local hostnames
  'staging' => array('your-staging-machine-name'),
  'production' => array('your-production-machine-name'),
));
0
votes

In case you test Laravel project using localhost domain or some other virtual hosts without dots (what I usually do), it might be helpful to use such code in bootstrap/start.php:

$env = $app->detectEnvironment(function(){
  if (strpos($_SERVER['HTTP_HOST'],'.') === false) {  
      return 'local';  
  }
  return 'production';
});

after:

$app = new Illuminate\Foundation\Application;

This makes that even you move your code into other directory or move to another machine/another virtual host without dots, you don't have to add machine name into local machines.

You can of course add more rules to that (include 127.0.0.1 or some hosts with .dev name) if you need.