Laravel Homestead: Use Environment Variables for Setting Environment

Submitted by hellossx - 9 years ago

This snippet will explain how to use environment variables to configure your environment. Blog post: http://dor.ky/laravel-homestead-add-enviroment-variables-to-nginx/

// Edit the website configuration name, by running the following command within the VM:
// $ sudo nano /etc/nginx/sites-available/local.dev

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

// location ~ \.php$ {
//     fastcgi_split_path_info ^(.+\.php)(/.+)$;
//     fastcgi_param LARAVEL_ENVIROMENT "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 enviroment:
$env = $app->detectEnvironment(function(){
    return getenv("LARAVEL_ENVIROMENT");
});