-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-apache-vhost
executable file
·66 lines (52 loc) · 1.63 KB
/
create-apache-vhost
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
60
61
62
63
64
65
66
#!/usr/bin/env php
<?php
if (!isset($argv[1])) {
echo "You need to set domain name, for example: create-apache-vhost.php mysite.ru\n";
exit(1);
}
$domain = $argv[1];
if (file_exists('/var/www/' . $domain)) {
echo "Domain $domain is exists.\n";
exit(1);
}
$conf = "
<VirtualHost *:88>
ServerAdmin webmaster@{$domain}
ServerName {$domain}
DocumentRoot /var/www/{$domain}/public
<Directory /var/www/{$domain}/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog \${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
#LogLevel warn
#CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
";
$htaccess = "
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
</IfModule>
";
$robotsTxt = "
# www.robotstxt.org/
# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449
User-Agent: *
Disallow: /cgi-bin/
Disallow: /admin/
";
file_put_contents('/etc/apache2/sites-enabled/' . $domain, $conf);
mkdir("/var/www/{$domain}");
mkdir("/var/www/{$domain}/public");
file_put_contents("/var/www/{$domain}/web/index.php", $domain . ' is under construction...');
file_put_contents("/var/www/{$domain}/web/.htaccess", $htaccess);
file_put_contents("/var/www/{$domain}/web/robots.txt", $robotsTxt);
system("chown -hR www-data:www-data /var/www/{$domain}/public");
//system('service apache2 reload');
system('/etc/init.d/apache2 reload');