Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 Environments not working

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,

like image 662
BigJobbies Avatar asked Mar 04 '14 16:03

BigJobbies


3 Answers

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

like image 90
angoru Avatar answered Nov 18 '22 02:11

angoru


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

like image 37
Kemal Fadillah Avatar answered Nov 18 '22 04:11

Kemal Fadillah


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'),
));
like image 1
sunzu Avatar answered Nov 18 '22 04:11

sunzu