-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-sites-available.php
59 lines (53 loc) · 1.68 KB
/
add-sites-available.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/* SCRIPT TO GENERATE VIRTUAL HOST FILES IN /etc/apache2/sites-available/
* NEEDS TO BE RUN AS SUDO
*****************************************************************************/
//SERVER ADMIN
$server_admin = '[email protected]';
//SITE DOMAIN
$site_domain = 'pj.passprotect.me';
//SITE PREFIXES
$site_prefixes = array(
'', //DEFAULT HOME
'db', //DIGITALBRANDS
'da', //DATING ADVICE
'pr', //PRINTAHOLIC
'cd', //COUPONSDAILY
'bc', //BADCREDIT
'cr', //CARDRATES
'gvs', //GAINESVILLESHOWS
'ha', //HOSTINGADVICE
'dc', //DEALCRUNCH
);
//Set port to argv or default to 80
$port = isset( $argv[1] ) ? $argv[1] : '80';
//PATH TO VIRTUAL HOST FILES
$path = '/etc/apache2/sites-available/';
//LOOP THORUGH EACH SITE AND CREATE THE VIRTUAL HOST FILE
$stdout = fopen('php://stdout', 'w');
foreach( $site_prefixes as $site_prefix ) :
$site_url = empty( $site_prefix ) ? $site_domain : $site_prefix . '.' . $site_domain;
$file_handle = fopen( $path . $site_url, 'w' );
fwrite( $stdout, "Writing file: $site_url\n" );
fwrite( $file_handle,
"<VirtualHost *:$port>
ServerAdmin $server_admin
ServerName $site_url
ServerAlias www.$site_url
DocumentRoot /home/sites/$site_url/public_html
ErrorLog /home/sites/$site_url/logs/error.log
CustomLog /home/sites/$site_url/logs/access.log combined
<Directory '/home/sites/$site_url/public_html'>
AuthName 'Password Protected Area'
AuthUserFile /home/.htpasswd
AuthType Basic
Require valid-user
AllowOverride All
</Directory>
</VirtualHost>");
fclose( $file_handle );
unset( $file_handle );
endforeach;
fwrite( $stdout, "\nDONE!!\n" );
fclose( $stdout );
?>