You can use the serve command to add new sites instead of running provision each time.
serve domain.app /home/vagrant/Code/path/to/public/directory 80
Hi all, thx for this great project.
I'm using Homestead from a while. I have a site with custom rewrite conditions, that i successfully put in my nginx configuration file. The problem borns when i start a new project, I provision the machine, and my custom settings will be overwrote with default settings.
Witch is for you the best way to avoid this?
Regards
You can use the serve command to add new sites instead of running provision each time.
serve domain.app /home/vagrant/Code/path/to/public/directory 80
Thank you! can be a good solution!
A perfect solution is to put somwere custom nginx rules in homestead / vagrant flies, so i can duplicate dev envoirnment without copy entire VM.
I agree with putting nginx rules in some homestead file instead of keeping it inside the vm.
For example location settings (like rewrite rules) for a specific domain.
I too am having this issue.
I want to add a custom global location to all my nginx vhosts and I can't find where to edit the "default nginx template" that the provisionner uses. Does anyone know where that's located?
Also, does using the serve command also add the entries to the Homestead.yaml ? If not.. then that's not very useful...
I have really been struggling with the fact that homestead provision is required to detect new changes in my .yaml file (which I make often) because everytime provision is run it does funky things like append the environmant variables to a configuration file inside /etc/php5 which causes a big mess in of itself.. and other things like overwriting nginx configuration and leaving dead bodies in the nginx folders (like if you removed entries from the .yaml, the provisionner doesn't clean up the nginx vhost folder). I suppose cleaning up would be destructive too but yea we really need an easier way of adding sites and adding custom configuration that persist when we have to add more new sites (in the form of entries in the .yaml)
I too have the same problem when I edit the nginx configuration file, it is reset upon provisioning homestead. So if I have a bunch of site, I have to save the configuration files and rewrite them after provisioning. Not ideal! Is there a workaround?
Any update on this? I have the same issue.
I would also like to show my support for this problem. There has to be way to modify your own nginx conf files. For instance enhancing the Homestead.yaml file section sites by adding key conf. So it would look something like this:
sites:
- map: test.app
to: /home/vagrant/Code/public
conf: /path/to/nginx/conf/on/local/machine/ #which could be a shell script
My solution to this issue, was that I modified the Homestead.rb file after line 125 where the sites web servers confs are executed based on the type of the server (laravel, symfony, hhvm). I added my own custom type there
if (type == "laravel-angular")
type = "laravel-angular"
end
and created shell script for that (laravel-angular.sh) and in Homestead.yaml file I gave the site my custom type so It would execute my custom shell script. I know that homestead has shell script that is executed after provisioning, which I could have used. But I couldn't figure out (found it harder) how to change the nginx conf file for specific site. I guess it is possible to read the same Homestead.yaml file into there and make changes based on that, but it seems way more difficult than my solution.
Hope it will help someone.
Thanks for sharing your solution @ronnkriibi but I am a bit confused by it and would really love it if you could clarify a few details.
Your 2nd piece of code I don't understand. If type == "xxx" then type = "xxx" how is that doing anything? Did you mean to use another variable then "type" in the condition?
Also you say that by then adding a .sh file with the same name as the type you set in the Homestead.rb file then you can create custom nginx configuration and place this outside the VM ?
Which folder exactly are you putting these files in?
If you could answer that would be very helpful. Thanks a lot!
My solution to this is to:
Create a directory structure under "~/.homestead" like "~/.homestead/setup/sites"
Create a copy of your custom nginx site file inside "~/.homestead/setup/sites" from "/etc/nginx/sites-available"
Add a directory mapping to your Homestead.yaml file located at: ~/.homestead/Homestead.yaml
For example, I use:
folders:
- map: ~/Dropbox/dev/Projects
to: /home/vagrant/Code
- map: ~/.homestead/setup
to: /home/vagrant/setup
# define your sites config directory located on your host machine
SITES=/home/vagrant/setup/sites/*
# copy every site file from /home/vagrant/setup/sites/ to your Nginx sites-available folder
yes | sudo cp -rf $SITES /etc/nginx/sites-available
# enable each site by creating a symbolic link to each file
for p in $SITES
do
FILE=$(basename $p)
sudo ln -s /etc/nginx/sites-available/$FILE /etc/nginx/sites-enabled/
done
# restart the nginx service
sudo service nginx restart
Next I'll experiment with creating a symbolic link from /home/vagrant/setup/sites/* to /etc/nginx/sites-enabled/ so hopefully we can just edit the site files on the host machine and the VM will reflect those changes after restarting the nginx service each time we make a change.
edit your ~/.composer/vendor/laravel/homestead/scripts/serve.sh file.
inside the template, add this code: include /etc/nginx/conf.d/$1-custom;
put it above the line that says "location ~.php$ {"
Then near the bottom of the file before the line that reads "service nginx restart", add this: touch "/etc/nginx/conf.d/$1-custom"
now, re-provision the machine. You can now store rewrite rules inside /etc/nginx/conf.d/yourdomain.com-custom and they will never get erased.
Here's a pastebin of my conf: http://pastebin.com/anbSkknu
If you have Homestead 3+ and install it like described in the Official Documentation, than you have an scripts folder in your Homestead directory (the cloned one).
In your Homestead.yaml file you can have a type property per site.
For example for a Kirby CMS installation, which is a great CMS by the way:
- map: kirby.dev
to: /home/vagrant/Dev/sandbox/kirby
type: kirby
If this type is set, Homestead looks on provision for a file called serve-yourType.sh - see here or defaults to serve-laravel.sh.
This means you can easily create your own file and access it via the type property per site. Simply copy serve-laravel.sh and make your changes.
Update I wrote about about this on Medium
Made my day
Please or to participate in this conversation.