Last active
January 15, 2016 12:36
-
-
Save atika/5bb1abe663536c2dbe44 to your computer and use it in GitHub Desktop.
Generate Vagrant/PuPHPet Nginx vhosts configuration for multiples sites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$websites = [ | |
["uid" => "mywebsite01", "name" => "mywebsite01.dev", "alias"=>"www.mywebsite01.dev", "root" => "/var/www/mywebsite01/www"], | |
["uid" => "mywebsite02", "name" => "mywebsite02.dev", "alias"=>"", "root" => "/var/www/mywebsite02/www"] | |
]; | |
$template = | |
" nxv__UID_: | |
server_name: _NAME_ | |
server_aliases: _ALIAS_ | |
www_root: _ROOT_ | |
listen_port: '80' | |
index_files: | |
- index.php | |
- index.html | |
- index.htm | |
client_max_body_size: 1m | |
ssl: '0' | |
ssl_cert: '' | |
ssl_key: '' | |
ssl_port: '443' | |
ssl_protocols: '' | |
ssl_ciphers: '' | |
rewrite_to_https: '1' | |
spdy: '1' | |
locations: | |
nxvl__UID01_: | |
location: / | |
autoindex: 'off' | |
internal: 'false' | |
try_files: | |
- \$uri | |
- \$uri/ | |
- /index.php\$is_args\$args | |
fastcgi: '' | |
fastcgi_index: '' | |
fastcgi_split_path: '' | |
proxy: '' | |
proxy_redirect: '' | |
nxvl__UID02_: | |
location: '~ \.php$' | |
autoindex: 'off' | |
internal: 'false' | |
try_files: | |
- \$uri | |
- \$uri/ | |
- /index.php\$is_args\$args | |
fastcgi: '127.0.0.1:9000' | |
fastcgi_index: index.php | |
fastcgi_split_path: '^(.+\.php)(/.*)$' | |
fast_cgi_params_extra: | |
- 'SCRIPT_FILENAME \$request_filename' | |
- 'APP_ENV dev' | |
proxy: '' | |
proxy_redirect: '' | |
"; | |
foreach ($websites as $key => $website) { | |
$uid01 = uniqid(); | |
$uid02 = uniqid(); | |
$search = ["_UID_","_NAME_","_ROOT_","_UID01_","_UID02_"]; | |
$replace = [$website['uid'], $website['name'], $website['root'], $uid01, $uid02]; | |
$content = str_replace($search, $replace, $template); | |
// alias | |
if (!empty($website['alias'])){ | |
$content = str_replace("_ALIAS_","\n - ".$website['alias'], $content); | |
}else{ | |
$content = str_replace("_ALIAS_","", $content); | |
} | |
echo $content; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment