Skip to content

Instantly share code, notes, and snippets.

@igidas
Last active February 20, 2019 14:03
Show Gist options
  • Save igidas/127c764e8753c6cc2e36 to your computer and use it in GitHub Desktop.
Save igidas/127c764e8753c6cc2e36 to your computer and use it in GitHub Desktop.
Easy multiple local projects development with Vagrant and Homestead. Automatic folder mapping and virtual domains ".dev". No touching of nginx and hosts configuration files.

http://www.sitepoint.com/set-automatic-virtual-hosts-nginx-apache/ http://laravel.com/docs/5.0/homestead http://passingcuriosity.com/2013/dnsmasq-dev-osx/

  1. Create folder "Development" and inside it create "Projects" and "Resources"
  2. Put contents of "nginx-dev" to "Developments/Resources/nginx-dev"
  3. Put contents of "nginx-projects" to "Developments/Resources/nginx-projects"
  4. Install laravel/Homstead
  5. Copy contents of "Homestead.yaml" to "~/.homestead/Homestead.yaml"
  6. Copy contents of "after.sh" to "~/.homestead/after.sh"
  7. Configure dnsmasq
  8. Optional: configure aliases in ".bash_profile"
  9. To create new project, create a folder "projectname.dev" in "Development/Projects". Put all projects files into "Development/Projects/projectname.dev/public".
  10. Navigate to "projectname.dev" on your browser.
# Vagrant Homestead
alias web_start='(cd ~/Development/Homestead; vagrant up)'
alias web_stop='(cd ~/Development/Homestead; vagrant suspend)'
alias web_reload='(cd ~/Development/Homestead; vagrant reload --provision)'
alias web_ssh='(cd ~/Development/Homestead; vagrant ssh)'
#!/bin/sh
# If you would like to do some extra provisioning you may
# add any commands you wish to this file and they will
# be run after the Homestead machine is provisioned.
# Add Wildcard server for auto project-server mapping in nginx
ln -fs "/home/vagrant/Resources/nginx-dev" "/etc/nginx/sites-enabled/nginx-dev"
ln -fs "/home/vagrant/Resources/nginx-projects" "/etc/nginx/sites-enabled/nginx-projects"
service nginx restart
service php5-fpm restart
---
ip: "192.168.10.10"
memory: 512
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Development/Projects
to: /home/vagrant/Projects
type: "nfs"
- map: ~/Development/Resources
to: /home/vagrant/Resources
type: "nfs"
sites:
- map: projects.dev
to: /home/vagrant/Projects/
databases:
- homestead
variables:
- key: 'APP_ENV'
value: 'local'
- key: 'APP_DEBUG'
value: 'true'
server {
listen 80;
# Server name wildcard. Use "project.dev" folder name for project
server_name ~^(www\.)?(?<sname>.+?)$;
root "/home/vagrant/Projects/$sname/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/$sname-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
server_name projects.dev www.projects.dev;
root "/home/vagrant/Projects";
charset utf-8;
access_log off;
error_log off;
location / {
autoindex on;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment