Skip to content

Instantly share code, notes, and snippets.

@clemblanco
Created November 26, 2014 14:55
Show Gist options
  • Save clemblanco/87cc3584521c8a872804 to your computer and use it in GitHub Desktop.
Save clemblanco/87cc3584521c8a872804 to your computer and use it in GitHub Desktop.
Homestead

Laravel Homestead

The official Laravel local development environment.

Official documentation is located here.

Self-Signed SSL Certificate

This Vagrant box is using SSL and an HTTPS server. If you update the stock Laravel Homestead box you'll have to re-create the self-signed SSL certificate.

sudi -i
mkdir /etc/nginx/ssl
cd /etc/nginx/ssl
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
service nginx restart
alias ..="cd .."
alias ...="cd ../.."
alias h='cd ~'
alias c='clear'
function serve() {
if [[ "$1" && "$2" ]]
then
sudo dos2unix /vagrant/scripts/serve.sh
sudo bash /vagrant/scripts/serve.sh "$1" "$2"
else
echo "Error: missing required parameters."
echo "Usage: "
echo " serve domain path"
fi
}
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Sites
to: /home/vagrant/Code
sites:
- map: ximbio.app
to: /home/vagrant/Code/ximbio/public
hhvm: true
- map: casewise.app
to: /home/vagrant/Code/casewise-licencing/public
hhvm: true
- map: harvestreports.app
to: /home/vagrant/Code/duck-reports-2014/public
hhvm: true
- map: nav.app
to: /home/vagrant/Code/need-a-valuation/public
hhvm: true
variables:
- key: APP_ENV
value: local
class Homestead
def Homestead.configure(config, settings)
# Configure The Box
config.vm.box = "laravel/homestead"
config.vm.hostname = "homestead"
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
# Configure A Few VirtualBox Settings
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", settings["memory"] ||= "2048"]
vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "1"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
# Configure Port Forwarding To The Box
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.network "forwarded_port", guest: 443, host: 44300
config.vm.network "forwarded_port", guest: 3306, host: 33060
config.vm.network "forwarded_port", guest: 5432, host: 54320
# Configure The Public Key For SSH Access
config.vm.provision "shell" do |s|
s.inline = "echo $1 | tee -a /home/vagrant/.ssh/authorized_keys"
s.args = [File.read(File.expand_path(settings["authorize"]))]
end
# Copy The SSH Private Keys To The Box
settings["keys"].each do |key|
config.vm.provision "shell" do |s|
s.privileged = false
s.inline = "echo \"$1\" > /home/vagrant/.ssh/$2 && chmod 600 /home/vagrant/.ssh/$2"
s.args = [File.read(File.expand_path(key)), key.split('/').last]
end
end
# Copy The Bash Aliases
config.vm.provision "shell" do |s|
s.inline = "cp /vagrant/aliases /home/vagrant/.bash_aliases"
end
# Register All Of The Configured Shared Folders
settings["folders"].each do |folder|
config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil
end
# Install All The Configured Nginx Sites
settings["sites"].each do |site|
config.vm.provision "shell" do |s|
s.inline = "bash /vagrant/scripts/serve.sh $1 $2"
s.args = [site["map"], site["to"]]
end
end
# Configure All Of The Server Environment Variables
if settings.has_key?("variables")
settings["variables"].each do |var|
config.vm.provision "shell" do |s|
s.inline = "echo \"\nenv[$1] = '$2'\" >> /etc/php5/fpm/php-fpm.conf && service php5-fpm restart"
s.args = [var["key"], var["value"]]
end
end
end
end
end
#!/usr/bin/env bash
block="
# HTTP server
server {
listen 80;
server_name $1;
root $2;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 16k;
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/$1-error.log error;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
client_max_body_size 100M;
}
# HTTPS server
server {
listen 443;
server_name $1;
root $2;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 16k;
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/$1-error.log error;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
}
"
echo "$block" > "/etc/nginx/sites-available/$1"
ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
service nginx restart
service php5-fpm restart
VAGRANTFILE_API_VERSION = "2"
path = "#{File.dirname(__FILE__)}"
require 'yaml'
require path + '/scripts/homestead.rb'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
Homestead.configure(config, YAML::load(File.read(path + '/Homestead.yaml')))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment