Mitesh Shah
12 years ago
11 changed files with 0 additions and 773 deletions
@ -1,39 +0,0 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* local environment values |
|||
*/ |
|||
$local_env['host'] = '191.168.1.199'; #ip of machine, this will be added to nginx config |
|||
$local_env['webroot'] = '/var/www'; #all websites will go hear |
|||
$local_env['htdocs'] = 'htdocs'; #name of directory which will act as document-root for a site |
|||
$local_env['logs'] = 'logs'; #name of directory which will store log files for a site |
|||
|
|||
$local_env['nginx_dir'] = '/etc/nginx'; #nginx conf dir |
|||
$local_env['nginx_user'] = 'www-data'; #nginx user |
|||
$local_env['nginx_group'] = 'www-data'; #nginx group |
|||
|
|||
$local_env['nginx_dir_sites_avilable'] = '/etc/nginx/sites-available'; #sites-avaialble |
|||
$local_env['nginx_dir_sites_enabled'] = '/etc/nginx/sites-enabled'; #sites-enable |
|||
|
|||
$local_env['default_conf'] = 'example.com'; #example configuration for wordpress |
|||
$local_env['default_domain'] = 'example.com'; #default domain in example.com |
|||
|
|||
$local_env['mysql_host'] = 'localhost'; #mysql host |
|||
$local_env['mysql_user'] = 'USER'; #mysql user |
|||
$local_env['mysql_pass'] = 'PASS'; #mysql pass |
|||
|
|||
$local_env['wp_latest'] = 'latest.zip'; #latest WordPress zip file |
|||
|
|||
|
|||
/** |
|||
* remote env - in scenario where you want to use move.php |
|||
* assumes - (1) remote DB allows remote connection |
|||
* (2) nginx & sites directory-structure is same |
|||
*/ |
|||
$remote_env['webroot'] = '/var/www'; //remote webroot - assuming similar directory sturcture |
|||
$remote_env['host'] = 'REMOTE_DBHOST'; //this is |
|||
$remote_env['ssh_user'] = 'REMOTE_DBUSER'; |
|||
$remote_env['ssh_pass'] = 'REMOTE_DBPASS'; |
|||
|
|||
|
|||
?> |
@ -1,158 +0,0 @@ |
|||
<?php |
|||
/* |
|||
CREATE A SITE WITH WORDPRESS |
|||
*/ |
|||
|
|||
include_once('init.php'); |
|||
|
|||
/** |
|||
* prompt user to eneter domain name |
|||
*/ |
|||
|
|||
echo "Enter a domain name which needs to be migrated...\n"; |
|||
$usr_domain = (trim(fgets(STDIN))); |
|||
echo "You have entered :: $usr_domain \n"; |
|||
|
|||
/* |
|||
* Set domain environment values |
|||
*/ |
|||
|
|||
$domain['name'] = $usr_domain; |
|||
$domain['conf'] = $local_env['nginx_dir_sites_avilable'] . '/' . $domain['name'] ; |
|||
$domain['rootdir'] = $local_env['webroot'] . '/' . $domain['name'] ; |
|||
$domain['htdocs'] = $domain['rootdir'] . '/' . $local_env['htdocs'] ; |
|||
$domain['logs'] = $domain['rootdir'] . '/' . $local_env['logs'] ; |
|||
|
|||
|
|||
/** |
|||
* Check if domain config file already exists |
|||
*/ |
|||
if (file_exists($domain['conf'])) { |
|||
echo "\nConfiguration files for domain '" . $domain['name'] . "'already exists :: " . $domain['conf']; |
|||
echo "\nDo you want to overwrite previous configuration? [Y/N] (default=Y)"; |
|||
|
|||
if (in_array(strtolower(fgets(STDIN)), array('n', 'no'))) { |
|||
die("\nYou choose to terminate this script! Bye-Bye!!! \n"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* At this point - either domain config file doesn't exist or user showed interest in overwriting it |
|||
* In either case... |
|||
* Create nginx conf for $domain in /etc/nginx/sites-available/$domain |
|||
* TODO :: Provide options to add supercache and/or w3total cache rules |
|||
*/ |
|||
/** |
|||
* Create config file |
|||
*/ |
|||
$nginx_conf = file_get_contents($local_env['default_conf']); |
|||
$nginx_conf = str_replace($local_env['default_domain'], $domain['name'], $nginx_conf); |
|||
file_put_contents($domain['conf'], $nginx_conf); |
|||
|
|||
//Error Check - if config file is created successfully or not |
|||
if (!file_exists($domain['conf'])) { |
|||
die("\nError encountered while creating " . $domain['conf']); |
|||
} |
|||
|
|||
/** |
|||
* Linking config file |
|||
*/ |
|||
echo "\nCreating Symbolic Link..\n"; |
|||
$command = "sudo ln -s " . $domain['conf'] . " " . $local_env['nginx_dir_sites_enabled']; |
|||
$result = system($command); |
|||
|
|||
//Error check - if linking config file succeed |
|||
if ($result != '') { |
|||
die("\nError encountered while creating script. Please check if file '" . $domain['conf'] . "'is created or not!\n"); |
|||
} |
|||
|
|||
//Go Ahead. |
|||
echo "Nginx configuration for '" . $domain['name'] . "' is created successfully"; |
|||
|
|||
/** |
|||
* Create webroot dirs for new domain |
|||
*/ |
|||
//create dirs |
|||
$result = system("mkdir " . $domain['rootdir']); |
|||
$result = system("mkdir " . $domain['htdocs']); |
|||
$result = system("mkdir " . $domain['logs']); |
|||
|
|||
//create log files |
|||
//in nginx folder |
|||
$result = system("touch " . "/var/log/nginx/" . $domain['name'] . ".access.log"); |
|||
$result = system("touch " . "/var/log/nginx/" . $domain['name'] . ".error.log"); |
|||
|
|||
//symlink |
|||
$result = system("ln -s " . "/var/log/nginx/" . $domain['name'] . ".access.log " . $domain['logs'] . "/access.log"); |
|||
$result = system("ln -s " . "/var/log/nginx/" . $domain['name'] . ".error.log " . $domain['logs'] . "/error.log"); |
|||
|
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while creating websites directories & files for " . $domain['name'] . "\n"); |
|||
} |
|||
|
|||
/** |
|||
* extract wordpress in new webroot dir |
|||
*/ |
|||
$command = "unzip -q -o " . $local_env['wp_latest'] . " -d " . $domain['htdocs'] . " > /dev/null"; |
|||
$result = system($command); |
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while extracting latest wordpress in directory " . $domain['rootdir'] . "\n"); |
|||
} |
|||
|
|||
$command = "mv " . $domain['htdocs'] . "/wordpress/* " . $domain['htdocs'] . "/"; |
|||
echo "\n COMMAND :: $command \n"; |
|||
$result = system($command); |
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while moving latest wordpress in directory " . $domain['rootdir'] . "\n" . $result); |
|||
} |
|||
|
|||
/** |
|||
* MySQL Creation |
|||
*/ |
|||
|
|||
$command = "mysql -h " . $local_env['mysql_host'] . " -u " . $local_env['mysql_user'] . " -p" . $local_env['mysql_pass'] . " -e 'create database `'" . $domain['name'] . "'` '"; |
|||
$result = system($command); |
|||
|
|||
/* |
|||
* Create wp-config.php |
|||
*/ |
|||
$wp_config_sample = $domain['htdocs'] . "/wp-config-sample.php"; |
|||
|
|||
$command = "sed s/database_name_here/{$domain['name']}/ $wp_config_sample | sed s/username_here/{$local_env['mysql_user']}/ | sed s/password_here/{$local_env['mysql_pass']}/ > {$domain['htdocs']}/wp-config.php"; |
|||
|
|||
$result = system($command); |
|||
|
|||
/** |
|||
* Chown |
|||
*/ |
|||
$command = "chown -R " . $local_env['nginx_user'] . ":" . $local_env['nginx_group'] . " " . $domain['rootdir']; |
|||
echo "\n COMMAND :: $command \n"; |
|||
$result = system($command); |
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while charging owner of " . $domain['rootdir'] . "\n" . $result); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* ALL SEENS WELL - Restart nginx |
|||
*/ |
|||
echo "\n Relaoding nginx configuration...\n\n"; |
|||
system('service nginx reload'); |
|||
|
|||
/** |
|||
* THE END |
|||
*/ |
|||
//just echo URL for new domain like http://$domain |
|||
//user will click it and verify if its working fine! ;-) |
|||
|
|||
echo $domain['name'] . " Successfully created\n\n"; |
|||
|
|||
?> |
@ -1,22 +0,0 @@ |
|||
server{ |
|||
server_name www.example.com example.com; |
|||
|
|||
access_log /var/log/nginx/example.com.access.log ; |
|||
error_log /var/log/nginx/example.com.error.log; |
|||
|
|||
root /var/www/example.com/htdocs; |
|||
index index.php index.html index.htm; |
|||
|
|||
## PHP with FATSCGI |
|||
location ~ \.php$ { |
|||
include /etc/nginx/fastcgi_params; |
|||
fastcgi_pass 127.0.0.1:9000; |
|||
fastcgi_index index.php; |
|||
} |
|||
|
|||
#root dir |
|||
location / { |
|||
autoindex on; |
|||
try_files $uri $uri/ /index.php; |
|||
} |
|||
} |
@ -1,54 +0,0 @@ |
|||
<?php |
|||
chdir(dirname(__FILE__)); |
|||
/* This will have configuration */ |
|||
// Report all PHP errors (see changelog) |
|||
error_reporting(E_ALL); |
|||
|
|||
if (file_exists('config.php')){ |
|||
include 'config.php'; |
|||
}else{ |
|||
die("Create a config.php to start with..."); |
|||
} |
|||
|
|||
/*** YOU CAN IGNORE ANYTHING BELOW THIS LINE **/ |
|||
|
|||
$hello = <<<EOF |
|||
.----------------. .----------------. .----------------. .----------------. .----------------. .----------------. |
|||
| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. | |
|||
| | _______ | || | _________ | || | ______ | || | __ | || | ____ ____ | || | ______ | | |
|||
| | |_ __ \ | || | | _ _ | | || | .' ___ | | || | / \ | || ||_ \ / _|| || | |_ __ \ | | |
|||
| | | |__) | | || | |_/ | | \_| | || | / .' \_| | || | / /\ \ | || | | \/ | | || | | |__) | | | |
|||
| | | __ / | || | | | | || | | | | || | / ____ \ | || | | |\ /| | | || | | ___/ | | |
|||
| | _| | \ \_ | || | _| |_ | || | \ `.___.'\ | || | _/ / \ \_ | || | _| |_\/_| |_ | || | _| |_ | | |
|||
| | |____| |___| | || | |_____| | || | `._____.' | || ||____| |____|| || ||_____||_____|| || | |_____| | | |
|||
| | | || | | || | | || | | || | | || | | | |
|||
| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' | |
|||
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------' |
|||
EOF; |
|||
|
|||
echo $hello . "\n"; |
|||
|
|||
/*** OK enough now. This is second & last time I am reminding YOU CAN IGNORE ANYTHING BELOW THIS LINE **/ |
|||
|
|||
|
|||
/* Useful test to avoid time-wastage */ |
|||
if($local_env['mysql_user'] == 'USER' || $local_env['mysql_pass'] == 'PASS'){ |
|||
die("Please enter mysql username & password before running this script."); |
|||
} |
|||
|
|||
if(!file_exists($local_env['wp_latest'])){ |
|||
echo "Latest WordPress is not present at " . $local_env['wp_latest'] ; |
|||
echo "Let me try downloading it…\n"; |
|||
$command = "wget http://wordpress.org/latest.zip -O " . $local_env['wp_latest'] ; |
|||
$result = system($command); |
|||
if(!file_exists($local_env['wp_latest'])){ |
|||
die ("this is second time I'm checking for WordPress but its missing at path " . $local_env['wp_latest'] . |
|||
"\n Please fix it first and then try running scripts here"); |
|||
}else{ |
|||
|
|||
echo "wordpress found at ". $local_env['wp_latest'] ; |
|||
} |
|||
} |
|||
|
|||
echo "\nconfig is correct.... go ahead my boy! \n"; |
|||
?> |
@ -1,156 +0,0 @@ |
|||
<?php |
|||
/* |
|||
MOVE A WORDPRESS SITE |
|||
THIS SCRIPT IS REALLY BROKEN. |
|||
*/ |
|||
|
|||
include_once('config.pgp'); |
|||
|
|||
|
|||
echo "\nEnter one or more domain names(s) which needs to be migrated...\n"; |
|||
echo "You can separate domain names by comma (,)...\n"; |
|||
echo "Example: google.com, yahoo.com,apple.com\n"; |
|||
|
|||
$usr_domain = (trim(fgets(STDIN))); |
|||
|
|||
$domain_arr = explode(",", $usr_domain); |
|||
|
|||
foreach($domain_arr as $domain){ |
|||
echo "****************************************************************************"; |
|||
echo "\n\nMoving :: $domain \n\n"; |
|||
move_domain(trim($domain)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* ALL SEENS WELL - Restart nginx |
|||
*/ |
|||
echo "\n Relaoding nginx configuration...\n\n"; |
|||
system('service nginx reload'); |
|||
|
|||
|
|||
|
|||
/** |
|||
* Function to move a single domain |
|||
* @param <type> $domain |
|||
*/ |
|||
function move_domain($usr_domain) { |
|||
global $local_env, $remote_env; |
|||
|
|||
if(trim($usr_domain) == ''){ |
|||
echo "\n CURRENT DOMAIN IS SKIPPED\n"; |
|||
return; |
|||
} |
|||
|
|||
/* |
|||
* Set domain environment values |
|||
*/ |
|||
$domain['name'] = $usr_domain; |
|||
$domain['conf'] = $local_env['nginx_dir_sites_avilable'] . '/' . $domain['name']; |
|||
$domain['rootdir'] = $local_env['webroot'] . '/' . $domain['name']; |
|||
$domain['htdocs'] = $domain['rootdir'] . '/' . $local_env['htdocs'] ; |
|||
$domain['logs'] = $domain['rootdir'] . '/' . $local_env['logs'] ; |
|||
|
|||
/** |
|||
* Check if domain config file already exists |
|||
*/ |
|||
if (file_exists($domain['conf'])) { |
|||
echo "\nConfiguration files for domain '" . $domain['name'] . "'already exists :: " . $domain['conf']; |
|||
echo "\nDo you want to overwrite previous configuration? [Y/N] (default=Y)"; |
|||
|
|||
if (in_array(strtolower(fgets(STDIN)), array('n', 'no'))) { |
|||
die("\nYou choose to terminate this script! Bye-Bye!!! \n"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* At this point - either domain config file doesn't exist or user showed interest in overwriting it |
|||
* In either case... |
|||
* Create nginx conf for $domain in /etc/nginx/sites-available/$domain |
|||
* TODO :: Provide options to add supercache and/or w3total cache rules |
|||
*/ |
|||
/** |
|||
* Create config file |
|||
*/ |
|||
$nginx_conf = file_get_contents($local_env['default_conf']); |
|||
$nginx_conf = str_replace($local_env['default_domain'], $domain['name'], $nginx_conf); |
|||
file_put_contents($domain['conf'], $nginx_conf); |
|||
|
|||
//Error Check - if config file is created successfully or not |
|||
if (!file_exists($domain['conf'])) { |
|||
die("\nError encounterd while creating " . $domain['conf']); |
|||
} |
|||
|
|||
/** |
|||
* Linking config file |
|||
*/ |
|||
echo "\nCreating Symbolic Link..\n"; |
|||
$command = "sudo ln -s " . $domain['conf'] . " " . $local_env['nginx_dir_sites_enabled']; |
|||
$result = system($command); |
|||
|
|||
//Error check - if linking config file succeed |
|||
if ($result != '') { |
|||
die("\nError encountered while creating script. Please check if file '" . $domain['conf'] . "'is created or not!\n"); |
|||
} |
|||
|
|||
//Go Ahead. |
|||
// echo "Nginx configuration for '" . $domain['name'] . "' is created successfully"; |
|||
|
|||
/** |
|||
* Create webroot dirs for new domain |
|||
*/ |
|||
//create dirs |
|||
$result = system("mkdir " . $domain['rootdir']); |
|||
$result = system("mkdir " . $domain['htdocs']); |
|||
$result = system("mkdir " . $domain['logs']); |
|||
|
|||
//create log files |
|||
$result = system("touch " . $domain['logs'] . "/access.log"); |
|||
$result = system("touch " . $domain['logs'] . "/error.log"); |
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while creating websites directories & files for " . $domain['name'] . "\n"); |
|||
} |
|||
|
|||
/** |
|||
* moving wordpress in new webroot dir |
|||
*/ |
|||
//export remote db |
|||
$command = "rsync --exclude '*.iso' -avz {$remote_env['ssh_user']}@{$remote_env['host']}:{$remote_env['webroot']}/{$domain['name']}/htdocs/* {$domain['htdocs']}/"; |
|||
$result = system($command); |
|||
|
|||
|
|||
/** |
|||
* MySQL Moving |
|||
*/ |
|||
$wp_config = get_defines($domain['htdocs'] . '/wp-config.php'); |
|||
|
|||
$command = "mysqldump -u {$wp_config['DB_USER']} -p{$wp_config['DB_PASSWORD']} -h {$remote_env['host']} --databases '{$wp_config['DB_NAME']}' > {$domain['rootdir']}/{$domain['name']}.sql"; |
|||
// echo "\n" . $command . "\n"; |
|||
$result = system($command); |
|||
|
|||
$command = "mysql -h {$local_env['mysql_host']} -u {$local_env['mysql_user']} -p{$local_env['mysql_pass']} < {$domain['rootdir']}/{$domain['name']}.sql"; |
|||
// echo "\n\n" . $command . "\n"; |
|||
$result = system($command); |
|||
|
|||
/* |
|||
* Create wp-config.php |
|||
*/ |
|||
//this may not be needed as we already have wp-config.php present for remote WordPress |
|||
//@TODO we need to replace DB_HOST though |
|||
|
|||
|
|||
/** |
|||
* Chown |
|||
*/ |
|||
$command = "chown -R " . $local_env['nginx_user'] . ":" . $local_env['nginx_group'] . " " . $domain['rootdir']; |
|||
echo "\n COMMAND :: $command \n"; |
|||
$result = system($command); |
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while chaging owner of " . $domain['rootdir'] . "\n" . $result); |
|||
} |
|||
} |
|||
?> |
@ -1,107 +0,0 @@ |
|||
<?php |
|||
include_once('init.php'); |
|||
|
|||
/* choice */ |
|||
$choice = ""; |
|||
|
|||
/** |
|||
* prompt user to eneter domain name |
|||
*/ |
|||
echo "Enter a domain name which needs to be removed...\n"; |
|||
$usr_domain = (trim(fgets(STDIN))); |
|||
|
|||
$domain_arr = explode(" ", $usr_domain); |
|||
|
|||
foreach($domain_arr as $domain){ |
|||
echo "****************************************************************************"; |
|||
echo "\n\nMoving :: $domain \n\n"; |
|||
remove_domain(trim($domain)); |
|||
} |
|||
|
|||
function remove_domain($usr_domain){ |
|||
global $local_env, $choice; |
|||
|
|||
echo "You have entered :: $usr_domain \n"; |
|||
|
|||
if(strlen($usr_domain) == 0 ){ |
|||
die("input cannot be empty!\n"); |
|||
} |
|||
|
|||
if(strpos($usr_domain,"..") !== false ){ |
|||
die("directory traversal is not allowed\n"); |
|||
} |
|||
|
|||
if(strpos($usr_domain,"\\") !== false ){ |
|||
die("domain cannot contain \\ !"); |
|||
} |
|||
|
|||
|
|||
/* |
|||
* Set domain environment values |
|||
*/ |
|||
|
|||
$domain['name'] = $usr_domain; |
|||
$domain['conf'] = $local_env['nginx_dir_sites_avilable'] . '/' . $domain['name'] ; |
|||
$domain['rootdir'] = $local_env['webroot'] . '/' . $domain['name'] ; |
|||
$domain['htdocs'] = $domain['rootdir'] . '/' . $local_env['htdocs'] ; |
|||
$domain['logs'] = $domain['rootdir'] . '/' . $local_env['logs'] ; |
|||
|
|||
|
|||
/** |
|||
* Check if domain config file already exists |
|||
*/ |
|||
echo "\n Domain Name - " . $domain['name'] . |
|||
"\n Webroot Dir - " . realpath($domain['rootdir']) . |
|||
"\n Database Name - " . $domain['name'] ; |
|||
|
|||
if($choice != "a"){ |
|||
//ask for confirmation |
|||
echo "\nDo you want to remove this domain, related files and databases for sure? [Y(es)/N(o)/A(lways)] (default=N): "; |
|||
|
|||
switch(strtolower(trim(fgets(STDIN)))){ |
|||
case 'y' : |
|||
die("\nYou choose to terminate this script! The domain is NOT removed! \n"); |
|||
|
|||
case 'a' : $choice = "a"; |
|||
} |
|||
} |
|||
|
|||
//remove htdocs |
|||
if(file_exists(realpath($domain['rootdir']))){ |
|||
if(dirname(realpath($domain['rootdir']))=="/var/www"){ |
|||
echo "/nremoving webroot \n"; |
|||
system("rm -rf ". $domain['rootdir']); |
|||
} |
|||
else |
|||
die("Try something else!"); |
|||
}else{ |
|||
echo "\n Directory " . $domain['rootdir'] . " doesn't exists\n"; |
|||
} |
|||
//delete database |
|||
$command = "mysql -h " . $local_env['mysql_host'] . " -u " . $local_env['mysql_user'] . " -p" . $local_env['mysql_pass'] . " -e 'drop database `'" . $domain['name'] . "'` '"; |
|||
$result = system($command); |
|||
|
|||
|
|||
/** |
|||
* Remove config file |
|||
*/ |
|||
if(file_exists($local_env['nginx_dir_sites_enabled']."/".$domain['name']) OR file_exists($local_env['nginx_dir_sites_avilable']."/".$domain['name'])){ |
|||
unlink($local_env['nginx_dir_sites_enabled']."/".$domain['name']); |
|||
unlink($local_env['nginx_dir_sites_avilable']."/".$domain['name']); |
|||
|
|||
}else{ |
|||
echo "\nNginx config files for $usr_domain domain do not exist\n"; |
|||
} |
|||
|
|||
|
|||
|
|||
}//end func |
|||
|
|||
/** |
|||
* ALL SEENS WELL - Restart nginx |
|||
*/ |
|||
echo "\n Issuing nginx reboot command...\n\n"; |
|||
system('service nginx restart'); |
|||
|
|||
|
|||
?> |
@ -1,11 +0,0 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* To change this template, choose Tools | Templates |
|||
* and open the template in the editor. |
|||
*/ |
|||
fwrite(STDOUT, "Enter your name\n"); // Output - prompt user |
|||
$name = fgets(STDIN); // Read the input |
|||
fwrite(STDOUT, "Hello $name"); // Output - Some text |
|||
exit(0); // Script ran OK |
|||
?> |
@ -1,123 +0,0 @@ |
|||
<?php |
|||
/* |
|||
CREATE A SITE WITH WORDPRESS |
|||
*/ |
|||
|
|||
include_once('init.php'); |
|||
|
|||
/** |
|||
* prompt user to eneter domain name |
|||
*/ |
|||
|
|||
echo "Enter a domain name which needs to be migrated...\n"; |
|||
$usr_domain = (trim(fgets(STDIN))); |
|||
echo "You have entered :: $usr_domain \n"; |
|||
|
|||
/* |
|||
* Set domain environment values |
|||
*/ |
|||
|
|||
$domain['name'] = $usr_domain; |
|||
$domain['conf'] = $local_env['nginx_dir_sites_avilable'] . '/' . $domain['name'] ; |
|||
$domain['rootdir'] = $local_env['webroot'] . '/' . $domain['name'] ; |
|||
$domain['htdocs'] = $domain['rootdir'] . '/' . $local_env['htdocs'] ; |
|||
$domain['logs'] = $domain['rootdir'] . '/' . $local_env['logs'] ; |
|||
|
|||
|
|||
/** |
|||
* Check if domain config file already exists |
|||
*/ |
|||
if (file_exists($domain['conf'])) { |
|||
echo "\nConfiguration files for domain '" . $domain['name'] . "'already exists :: " . $domain['conf']; |
|||
echo "\nDo you want to overwrite previous configuration? [Y/N] (default=Y)"; |
|||
|
|||
if (in_array(strtolower(fgets(STDIN)), array('n', 'no'))) { |
|||
die("\nYou choose to terminate this script! Bye-Bye!!! \n"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* At this point - either domain config file doesn't exist or user showed interest in overwriting it |
|||
* In either case... |
|||
* Create nginx conf for $domain in /etc/nginx/sites-available/$domain |
|||
* TODO :: Provide options to add supercache and/or w3total cache rules |
|||
*/ |
|||
/** |
|||
* Create config file |
|||
*/ |
|||
$nginx_conf = file_get_contents($local_env['default_conf']); |
|||
$nginx_conf = str_replace($local_env['default_domain'], $domain['name'], $nginx_conf); |
|||
file_put_contents($domain['conf'], $nginx_conf); |
|||
|
|||
//Error Check - if config file is created successfully or not |
|||
if (!file_exists($domain['conf'])) { |
|||
die("\nError encountered while creating " . $domain['conf']); |
|||
} |
|||
|
|||
/** |
|||
* Linking config file |
|||
*/ |
|||
echo "\nCreating Symbolic Link..\n"; |
|||
$command = "sudo ln -s " . $domain['conf'] . " " . $local_env['nginx_dir_sites_enabled']; |
|||
$result = system($command); |
|||
|
|||
//Error check - if linking config file succeed |
|||
if ($result != '') { |
|||
die("\nError encountered while creating script. Please check if file '" . $domain['conf'] . "'is created or not!\n"); |
|||
} |
|||
|
|||
//Go Ahead. |
|||
echo "Nginx configuration for '" . $domain['name'] . "' is created successfully"; |
|||
|
|||
/** |
|||
* Create webroot dirs for new domain |
|||
*/ |
|||
//create dirs |
|||
$result = system("mkdir " . $domain['rootdir']); |
|||
$result = system("mkdir " . $domain['htdocs']); |
|||
$result = system("mkdir " . $domain['logs']); |
|||
|
|||
//create log files |
|||
$result = system("touch " . $domain['logs'] . "/access.log"); |
|||
$result = system("touch " . $domain['logs'] . "/error.log"); |
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while creating websites directories & files for " . $domain['name'] . "\n"); |
|||
} |
|||
|
|||
/** |
|||
* MySQL Creation |
|||
*/ |
|||
|
|||
$command = "mysql -h " . $local_env['mysql_host'] . " -u " . $local_env['mysql_user'] . " -p" . $local_env['mysql_pass'] . " -e 'create database `'" . $domain['name'] . "'` '"; |
|||
$result = system($command); |
|||
|
|||
/** |
|||
* Chown |
|||
*/ |
|||
$command = "chown -R " . $local_env['nginx_user'] . ":" . $local_env['nginx_group'] . " " . $domain['rootdir']; |
|||
echo "\n COMMAND :: $command \n"; |
|||
$result = system($command); |
|||
|
|||
//Error check |
|||
if ($result != '') { |
|||
die("\nError encountered while charging owner of " . $domain['rootdir'] . "\n" . $result); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* ALL SEENS WELL - Restart nginx |
|||
*/ |
|||
echo "\n Relaoding nginx configuration...\n\n"; |
|||
system('service nginx reload'); |
|||
|
|||
/** |
|||
* THE END |
|||
*/ |
|||
//just echo URL for new domain like http://$domain |
|||
//user will click it and verify if its working fine! ;-) |
|||
|
|||
echo $domain['name'] . " Successfully created\n\n"; |
|||
|
|||
?> |
@ -1,65 +0,0 @@ |
|||
#!/bin/bash |
|||
#This script makes virtual host, site directories and log files |
|||
#Author : Pragati Sureka |
|||
|
|||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then |
|||
echo "make_vsite:You need to run this script as root(or use sudo)" |
|||
exit |
|||
fi |
|||
|
|||
# Check for proper number of command line args. |
|||
if [ $# -ne 1 ] |
|||
then |
|||
echo "Usage: `basename $0` example.com" |
|||
echo " <example.com should be replaced by actual domain name>" |
|||
exit |
|||
fi |
|||
|
|||
sed s/[[:blank:]]*//g $1 > $1 |
|||
|
|||
#Script Variables |
|||
WEBROOT="/var/www" |
|||
SKELFILE="/etc/nginx/sites-available/example.com" |
|||
VSITEDIR="/etc/nginx/sites-available" |
|||
ESITEDIR="/etc/nginx/sites-enabled" |
|||
USER="www-data" |
|||
GROUP="www-data" |
|||
SERVER_RELOAD="service nginx restart" |
|||
WP_ZIP="/home/rtcamp/wordpress/latest.zip" #wordpress 3.0 |
|||
|
|||
#make directories and touch log files |
|||
mkdir $WEBROOT/$1 |
|||
mkdir $WEBROOT/$1/htdocs |
|||
mkdir $WEBROOT/$1/logs |
|||
touch $WEBROOT/$1/logs/error.log |
|||
touch $WEBROOT/$1/logs/access.log |
|||
|
|||
#download latest wordpress and extract it to proper location |
|||
cd $WEBROOT/$1 |
|||
#wget www.wordpress.org/latest.zip |
|||
unzip -q -o $WP_ZIP |
|||
mv wordpress/* htdocs/ |
|||
rm -rf $WEBROOT/$1/wordpress |
|||
#rm $WEBROOT/$1/latest.zip |
|||
chown -R $USER:$GROUP $WEBROOT/$1 |
|||
#chmod g+rw -R $WEBROOT/$1 |
|||
|
|||
#create database |
|||
mysql -u USER -pPASS -e 'create database `'$1'` ' |
|||
|
|||
#create wp-config.php file |
|||
CONFIGSAMPLE=$WEBROOT/$1/htdocs/wp-config-sample.php |
|||
sed s/database_name_here/$1/ $CONFIGSAMPLE | sed s/username_here/USER/ | sed s/password_here/PASS/ > $WEBROOT/$1/htdocs/wp-config.php |
|||
|
|||
#copy skeleton file and enable site |
|||
sed s/example.com/$1/ $SKELFILE > $VSITEDIR/$1 |
|||
ln -s $VSITEDIR/$1 $ESITEDIR/ |
|||
echo "127.0.0.1 $1" >> /etc/hosts |
|||
$SERVER_RELOAD |
|||
if [ $? -ne 0 ]; then |
|||
#rm -rf $WEBROOT/$1 |
|||
unlink $ESITEDIR/$1 |
|||
$SERVER_RELOAD |
|||
sed -i".bak" '$d' /etc/hosts |
|||
echo "ERROR CREATING PLEASE CONTACT pragati.sureka@rtcamp.com FOR ASSISTANCE!" |
|||
fi |
@ -1,35 +0,0 @@ |
|||
#!/bin/bash |
|||
#This script makes virtual host, site directories and log files |
|||
#Author : Pragati Sureka, rahul286 |
|||
|
|||
if [[ $(/usr/bin/id -u) -ne 0 ]]; then |
|||
echo "make_vsite:You need to this script as root(or use sudo)" |
|||
exit |
|||
fi |
|||
|
|||
#Script Variables |
|||
WEBROOT="/var/www" |
|||
SKELFILE="/etc/apache2/sites-available/skeleton" |
|||
VSITEDIR="/etc/apache2/sites-available" |
|||
USER="www-data" |
|||
GROUP="www-data" |
|||
SERVER_RELOAD="/etc/init.d/apache2 reload" |
|||
|
|||
#make directories and touch log files |
|||
mkdir $WEBROOT/$1 |
|||
mkdir $WEBROOT/$1/htdocs |
|||
mkdir $WEBROOT/$1/logs |
|||
touch $WEBROOT/$1/logs/error.log |
|||
touch $WEBROOT/$1/logs/custom.log |
|||
|
|||
#copy skeleton file and enable site |
|||
sed s/site/$1/ $SKELFILE > $VSITEDIR/$1 |
|||
a2ensite $1 &> /dev/null |
|||
echo "127.0.0.1 $1" >> /etc/hosts |
|||
$SERVER_RELOAD &> /dev/null |
|||
if [ $? -ne 0 ]; then |
|||
rm -rf $WEBROOT/$1 |
|||
a2dissite $1 |
|||
sed -i".bak" '$d' /etc/hosts |
|||
echo "ERROR CREATING PLEASE CONTACT pragati.sureka@rtcamp.com FOR ASSISTANCE!" |
|||
fi |
@ -1,3 +0,0 @@ |
|||
service mysql stop |
|||
service php5-fpm restart |
|||
service mysql start |
Loading…
Reference in new issue