Laravel Homestead: Add Enviroment Variables to Nginx

If you wish to set your environment by using server environmental variables with the new Laravel Homestead you can do the following:

Edit the website configuration name, by running the following command within the VM:

$ sudo nano /etc/nginx/sites-available/

Within the location ~ .php$ { block, update your configuration to resemble this:

location ~ .php$ {
    fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param LARAVEL_ENVIRONMENT "dev";

fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;


Now restart Nginx

$ sudo /etc/init.d/nginx restart

Next, edit your bootstrap/start.php file and update the method to detect environment:

$env = $app->detectEnvironment(function(){
    return getenv("LARAVEL_ENVIRONMENT");

Now you can set your environments per server.