Laravel Homestead -- The missing manual part 1 -- Site Parameters

Joe • February 23, 2018

laravel linux projects ubuntu vagrant

In the early days of Homestead there used to be a "params" option at the top level of your Homestead.yaml file. These parameters would be copied into the environment for the virtual machine just like you would set environment variables on your production systems. Laravel ultimately moved to using ".env" files and this feature was removed from Homestead.

Some users pushed back and still wanted to be able to easily push parameters to the individual site's configuration file (virtual host file) so a new feature was implemented where you could add a "params" key to your Homestead.yaml site definition and they would be copied into the virtual host configuration file. To get started using this feature simply add the "params" block to a site definition in Homestead.yaml:

    - map: qs.test
      to: /home/vagrant/qs/public
            - key: key_1
              value: value_1
            - key: key_2
              value: value_2

Run "vagrant destroy && vagrant up" and when the machine comes back up, we can inspect our virtual host file at "/etc/nginx/sites-available/qs.test":

location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

      fastcgi_param key_1 value_1;
      fastcgi_param key_2 value_2;

        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;

This feature also works for sites using Apache instead of Nginx.