-
Notifications
You must be signed in to change notification settings - Fork 0
/
apache_vhost_cr.pl
54 lines (34 loc) · 1014 Bytes
/
apache_vhost_cr.pl
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
#!/usr/bin/perl
use strict;
use warnings;
print"Please insert the host name: \n";
my $name = <STDIN>;
chomp($name);
my $USER ='$USER';
my $conf =qq(
<VirtualHost *:80>
ServerAdmin admin\@test.com
ServerName www.$name.com
ServerAlias $name.com
DocumentRoot /var/www/$name/
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
); <h1>
my $conf_name ="/etc/apache2/sites-available/$name.conf";
my $index = "/var/www/$name/index.html";
print"Start work!!!\n";
`mkdir -p /var/www/$name/`;
open(FH, '>', $index) or die $!;
print FH "<h1>This is $name </h1>";
<h1>
close FH;
`sudo chown -R $USER:$USER /var/www/$name`;
`sudo chmod -R 755 /var/www/$name`;
open(FH, '>', $conf_name) or die $!;
print FH $conf;
close FH;
`sudo a2dissite 000-default.conf`;
`sudo a2ensite $name.conf`;
`apachectl restart`;
print"Apache Virtual host was created!!! \n Please insert in ~/hosts the following: 'i.p.address www.\$name.com'\n";