-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymWebDevInstaller.php
208 lines (163 loc) · 5.63 KB
/
SymWebDevInstaller.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/*
* This file is part of the symfony Web Development Environment Installer.
* (c) Pablo Godel <[email protected]>
* ServerGrove.com
*
* Use it at your own risk.
*/
if (!$this->askConfirmation('
Welcome to the Symfony Web Developent Environment installer!
This installer will perform the following steps:
- setup hosts file
- Add virtual host configuration to Apache web server
- Restart Apache
Keep in mind that you need to have permissions to modify the respective files and restart Apache.
You will be prompted to enter the IP address, hostname, and asked to confirm each operation. You can skip each step as desired.
Do you wish to continue on with the installation? (y/n)'))
{
$this->logBlock('Symfony Web Developent Environment installation was cancelled!', 'ERROR_LARGE');
return;
}
$projectName = $this->arguments['name'];
$documentRoot = sfConfig::get('sf_web_dir');
$defaultIp = '127.0.0.1';
$defaultHostname = $projectName.'.local';
$isWindows = false;
$isLinux = false;
if ( isset( $_SERVER['SystemRoot'] ) )
{
$isWindows = true;
$winDir = $_SERVER['SystemRoot'];
$this->logBlock("Windows OS detected at $winDir", 'INFO');
}
else
{
$linux = exec( 'uname', $output );
$isLinux = strpos( $output[0], 'Linux' ) !== false;
}
$ipAddress = $this->askAndValidate('What is the IP address for your web project (default: '.$defaultIp.')?'
, new sfValidatorString( array( 'empty_value' => $defaultIp, 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
$this->logBlock("IP address set to $ipAddress", 'INFO');
$hostname = $this->askAndValidate('What is the hostname for your web project (default: '.$defaultHostname.')?'
, new sfValidatorString( array( 'empty_value' => $defaultHostname, 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
$this->logBlock("Hostname set to $hostname", 'INFO');
$apacheConfFile = $this->askAndValidate('Enter the full file name of Apache Web Server configuration file (default: auto-search)?'
, new sfValidatorString( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
$this->logBlock( empty( $apacheConfFile ) ? "Will search for Apache configuration" : "Apache configuration set to $apacheConfFile", 'INFO');
if ( $isWindows )
{
$hostsFile = $winDir.'\system32\drivers\etc\hosts';
}
else
{
$hostsFile = '/etc/hosts';
}
if ( ! file_exists( $hostsFile ) )
{
$hostsFile = $this->askAndValidate('Could not find hosts file. Please provide the full path name of the hosts file (press enter to skip this step)'
, new sfValidatorFile( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
}
else
{
$this->logBlock("hosts file set to $hostsFile", 'INFO');
}
$content = "
# Added by Symfony Web Developent Environment installer
$ipAddress $hostname
";
if ( !empty( $hostsFile )
&& file_exists( $hostsFile )
&& $this->askConfirmation("Add '$ipAddress $hostname' to hosts file located at $hostsFile? (y/n)", 'QUESTION_LARGE'))
{
if ( ! file_put_contents ( $hostsFile, $content, FILE_APPEND ) )
{
$this->logBlock("Failed to add $content to hosts file at $hostsFile. Please check that you have permissions to update this file.", 'ERROR_LARGE');
}
else
{
$this->logBlock("hosts file modified successfully.", 'INFO');
}
}
else
{
$this->logBlock("Skipped modifying hosts file.", 'INFO');
}
if ( empty( $apacheConfFile ) || ! file_exists( $apacheConfFile ) )
{
$this->logBlock("Searching for Apache web server configuration file", 'INFO');
if ( $isWindows )
{
$possibleLocations = array(
'C:\Program Files\Zend\Apache2\conf\httpd.conf',
);
}
else
{
$possibleLocations = array(
'/etc/httpd/conf/httpd.conf',
'/etc/apache2/conf/apache.conf',
'/usr/local/apache2/conf/httpd.conf',
'/usr/local/apache/conf/httpd.conf',
'/usr/local/zend/apache2/conf/httpd.conf',
);
}
foreach ($possibleLocations as $path )
{
if ( file_exists( $path ) )
{
$apacheConfFile = $path;
$this->logBlock("Apache configuration found at $apacheConfFile", 'INFO');
break;
}
}
}
if ( ! file_exists( $apacheConfFile ) )
{
$hostsFile = $this->askAndValidate('Could not find hosts file. Please provide the full path name of the hosts file'
, new sfValidatorFile( array( 'required' => false ) ), array('style' => 'QUESTION_LARGE'));
}
$content = '
# Added by Symfony Web Developent Environment installer
<VirtualHost *:80>
DocumentRoot "'.$documentRoot.'"
ServerName '.$hostname.'
</VirtualHost>
<Directory "'.$documentRoot.'">
AllowOverride All
</Directory>
';
if ( !empty( $apacheConfFile )
&& file_exists( $apacheConfFile )
&& $this->askConfirmation("Add Virtual Host section to $apacheConfFile? (y/n)", 'QUESTION_LARGE'))
{
if ( ! file_put_contents ( $apacheConfFile, $content, FILE_APPEND ) )
{
$this->logBlock("Failed to add configuration to $apacheConfFile. Please check that you have permissions to update this file.", 'ERROR_LARGE');
}
else
{
$this->logBlock("Apache configured successfully.", 'INFO');
}
}
if ($this->askConfirmation("Do you want to restart Apache to load the new configuration? (y/n)", 'QUESTION_LARGE'))
{
$cmd = '';
if ( $isLinux )
{
$cmd = "service httpd restart";
}
if ( empty( $cmd ) )
{
$this->logBlock("Could not find a way to restart Apache. Please restart it manually.", 'ERROR_LARGE');
}
else
{
if ( ! passthru( $cmd ) )
{
$this->logBlock("Failed to restart Apache. Please check that you have permissions to restart Apache.", 'ERROR_LARGE');
return;
}
}
}
$this->logBlock("Symfony Web Development environemnt all setup. Go to http://$hostname/", 'INFO');