Usage:
- copy
wp-mu.conf-sample
toconfig/nginx-config/sites/wp-mu.conf-sample
- copy
make-vvv.js
to VVV root - Run
node make-vvv.js your-client project-name
Don't forget to restart your vagrant (vagrant reload --provision
)
var fs = require('fs'); | |
var path = require('path'); | |
var readline = require('readline'); | |
var args = process.argv.slice(2); | |
var clientName, projectName; | |
clientName = projectName = args[0]; | |
if( args[1] ){ | |
projectName = args[1]; | |
} | |
var dbName = clientName + '_' + projectName; | |
var nginxConfigPath = "config/nginx-config/sites/" + dbName + ".conf"; | |
if( fs.existsSync(nginxConfigPath) ){ | |
console.log('Project already exists'); | |
return; | |
} | |
console.log('Creating project: ', projectName); | |
var nginxConfig = fs.readFileSync( "config/nginx-config/sites/wp-mu.conf-sample", "utf8" ); | |
nginxConfig = nginxConfig.replace(/\{\{__client__\}\}/g, clientName); | |
nginxConfig = nginxConfig.replace(/\{\{__project__\}\}/g, projectName); | |
fs.writeFileSync( nginxConfigPath, nginxConfig, 'utf8'); | |
var database = "\n\nCREATE DATABASE IF NOT EXISTS `" + dbName + "`;\n"; | |
database += "GRANT ALL PRIVILEGES ON `" + dbName + "`.* TO 'wp'@'localhost' IDENTIFIED BY 'wp';"; | |
fs.appendFileSync("database/init-custom.sql", database, 'utf8'); | |
var projectPath = 'www'; | |
var projectPathParts = [ clientName, projectName ]; | |
for (var i = 0; i < projectPathParts.length; i++) { | |
projectPath += path.sep + projectPathParts[i]; | |
if( !fs.existsSync( projectPath ) ){ | |
fs.mkdirSync( projectPath ) | |
} | |
}; | |
var hostsFile = "www/" + clientName + "/vvv-hosts"; | |
var hostFileEntry = "\n" + projectName + ".wordpress.dev"; | |
if( fs.existsSync(hostsFile) ){ | |
fs.appendFileSync( hostsFile, hostFileEntry, 'utf8'); | |
}else { | |
fs.writeFileSync( hostsFile, hostFileEntry, 'utf8'); | |
} |
server { | |
listen 80; | |
listen 443 ssl; | |
server_name {{__project}}.wordpress.dev *.{{__project}}.wordpress.dev; | |
root /srv/www/{{__client__}}/{{__project}}; | |
include /etc/nginx/nginx-wp-common.conf; | |
if (!-e $request_filename) { | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
rewrite ^(/[^/]+)?(/wp-.*) $2 last; | |
rewrite ^(/[^/]+)?(/.*\.php) $2 last; | |
} | |
location ~ \.php$ { | |
try_files $uri /index.php; | |
include fastcgi_params; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
} | |
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { | |
access_log off; log_not_found off; expires max; | |
} | |
location = /robots.txt { access_log off; log_not_found off; } | |
location ~ /\. { deny all; access_log off; log_not_found off; } | |
access_log /srv/www/{{__client__}}/{{__project}}/access.log; | |
error_log /srv/www/{{__client__}}/{{__project}}/error.log; | |
} |