forked from Mark-H/MODX-Installers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-core.php
217 lines (183 loc) · 8.04 KB
/
install-core.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
209
210
211
212
213
214
215
216
217
<?php
/**
* MODX CORE INSTALLER
*
* @author Bert Oost at OostDesign.com <[email protected]>
*/
$isNewInstall = true;
require_once(dirname(__FILE__) . '/includes/initializer.php');
// ask the necessary data
$_config['mysql']['NAME'] = readQuestion('Enter the database name', 'any');
$projecthost = readQuestion('Enter project host (eq. x.yourname.com)', 'any');
$projectalias = readQuestion('Enter project alias (eq. x.yourname.nl)', 'any');
// MODX admin user
$adminUser = $_config['modx']['username'];
$adminUser = (!empty($adminUser)) ? $adminUser : 'admin';
// MODX admin password
$adminPassword = $_config['modx']['password'];
$adminPassword = (!empty($adminPassword)) ? $adminPassword : generatePassword();
// MODX admin email
$adminEmail = $_config['modx']['email'];
//if(!isset($adminEmail) || empty($adminEmail)) {
while(empty($adminEmail)) {
$adminEmail = readQuestion('Please enter the MODX Manager emailaddress', 'any');
}
// Creating project root path
echo date('Y-m-d H:i:s').' [INFO] Creating project directory...'."\n";
mkdir($projectpath, 0755, true);
chdir($projectpath); // moves PHP to project path
$out = exec('cd '.$projectpath); // moves environment to project path
// --------------------------
// APACHE VHS
if(strtolower($_config['apacheCreateVHS']) == 'yes') {
// create virtualhost file
echo date('Y-m-d H:i:s').' [INFO] Creating Apache VirtualHost file...'."\n";
$tplFile = dirname(__FILE__).'/templates/vhs.apache.tpl';
if(!empty($projectalias)) {
$tplFile = dirname(__FILE__).'/templates/vhs.apache.alias.tpl';
}
if(file_exists($tplFile)) {
$vhfileContents = file_get_contents($tplFile);
$vhfileContents = str_replace('{projecthost}', $projecthost, $vhfileContents);
$vhfileContents = str_replace('{projectalias}', $projectalias, $vhfileContents);
$vhfileContents = str_replace('{projectpath}', $projectpath, $vhfileContents);
}
else {
$vhfileContents = "<VirtualHost *:80>\n
\tServerName {$projecthost}\n".
((!empty($projectalias)) ? "\tServerAlias {$projectalias}\n" : '')
."\tDocumentRoot {$projectpath}\n
</VirtualHost>";
}
$hostsfile = $_config['apache']['VHS'].$projecthost;
$idx = 1;
while(file_exists($hostsfile)) {
$hostsfile = $_config['apache']['VHS'].$projecthost.'.'.$idx;
$idx++;
}
$fh = fopen($hostsfile, "w+");
fwrite($fh, $vhfileContents);
fclose($fh);
// time to reload Apache
if(isset($_config['apache']['ACTIVE']) && $_config['apache']['ACTIVE'] == 'yes') {
echo date('Y-m-d H:i:s').' [INFO] Reloading Apache...'."\n";
if(isset($_config['apache']['RELOAD_CMD']) && !empty($_config['apache']['RELOAD_CMD'])) {
$out = exec($_config['apache']['RELOAD_CMD']);
} else {
echo date('Y-m-d H:i:s').' [ERROR] Unable to reload Apache, please reload it yourself...'."\n";
}
}
}
// --------------------------
// NGINX VHS
if(strtolower($_config['nginxCreateVHS']) == 'yes') {
// create virtualhost file
echo date('Y-m-d H:i:s').' [INFO] Creating NginX server block (virtualhost) file...'."\n";
$tplFile = dirname(__FILE__).'/templates/vhs.nginx.tpl';
if(!empty($projectalias)) {
$tplFile = dirname(__FILE__).'/templates/vhs.nginx.alias.tpl';
}
if(file_exists($tplFile)) {
$vhfileContents = file_get_contents($tplFile);
$vhfileContents = str_replace('{projecthost}', $projecthost, $vhfileContents);
$vhfileContents = str_replace('{projectalias}', $projectalias, $vhfileContents);
$vhfileContents = str_replace('{projectpath}', $projectpath, $vhfileContents);
}
else {
$vhfileContents = "server {\n
\tlisten 80;
\tserver_name {$projecthost}".((!empty($projectalias)) ? " {$projectalias}" : '').";\n
\troot {$projectpath};\n
\tlocation / {
\t\tif (!-e $request_filename) {
\t\t\trewrite ^/(.*)$ /index.php?q=$1 last;
\t\t}
\t}
}";
}
$hostsfile = $_config['nginx']['VHS'].$projecthost;
$idx = 1;
while(file_exists($hostsfile)) {
$hostsfile = $_config['nginx']['VHS'].$projecthost.'.'.$idx;
$idx++;
}
$fh = fopen($hostsfile, "w+");
fwrite($fh, $vhfileContents);
fclose($fh);
// time to reload Apache
if(isset($_config['nginx']['ACTIVE']) && $_config['nginx']['ACTIVE'] == 'yes') {
echo date('Y-m-d H:i:s').' [INFO] Reloading NginX...'."\n";
if(isset($_config['nginx']['RELOAD_CMD']) && !empty($_config['nginx']['RELOAD_CMD'])) {
$out = exec($_config['nginx']['RELOAD_CMD']);
} else {
echo date('Y-m-d H:i:s').' [ERROR] Unable to reload NginX, please reload it yourself...'."\n";
}
}
}
// Creating config xml to install MODX with
echo date('Y-m-d H:i:s').' [INFO] Creating MODX install config XML...'."\n";
$configXMLContents = "<modx>
<database_type>mysql</database_type>
<database_server>localhost</database_server>
<database>{$_config['mysql']['NAME']}</database>
<database_user>{$_config['mysql']['USER']}</database_user>
<database_password>{$_config['mysql']['PASS']}</database_password>
<database_connection_charset>utf8</database_connection_charset>
<database_charset>utf8</database_charset>
<database_collation>utf8_general_ci</database_collation>
<table_prefix>modx_</table_prefix>
<https_port>443</https_port>
<http_host>{$projecthost}</http_host>
<cache_disabled>0</cache_disabled>
<inplace>1</inplace>
<unpacked>0</unpacked>
<language>en</language>
<cmsadmin>{$adminUser}</cmsadmin>
<cmspassword>{$adminPassword}</cmspassword>
<cmsadminemail>{$adminEmail}</cmsadminemail>
<core_path>{$projectpath}core/</core_path>
<context_mgr_path>{$projectpath}manager/</context_mgr_path>
<context_mgr_url>/manager/</context_mgr_url>
<context_connectors_path>{$projectpath}connectors/</context_connectors_path>
<context_connectors_url>/connectors/</context_connectors_url>
<context_web_path>{$projectpath}</context_web_path>
<context_web_url>/</context_web_url>
<remove_setup_directory>1</remove_setup_directory>
</modx>";
$fh = fopen('config.xml', "w+");
fwrite($fh, $configXMLContents);
fclose($fh);
// Creating the new database
echo date('Y-m-d H:i:s').' [INFO] Creating database '.$_config['mysql']['NAME'].'...'."\n";
$out = exec("mysql --user={$_config['mysql']['USER']} --password={$_config['mysql']['PASS']} -e \"CREATE DATABASE IF NOT EXISTS {$_config['mysql']['NAME']} CHARACTER SET utf8 COLLATE utf8_general_ci;\"");
// Get latest MODX
echo date('Y-m-d H:i:s').' [INFO] Getting latest MODX version from modx.com...'."\n";
$out = exec('wget -O modx.zip http://modx.com/download/latest/');
echo date('Y-m-d H:i:s').' [INFO] Unzipping MODX package...'."\n";
$out = exec('unzip modx.zip');
$_ZDIR = exec('ls -F | grep "\/" | head -1');
if($_ZDIR == '/') {
die(date('Y-m-d H:i:s').' [ERROR] Cannot find unzipped MODX folder...'."\n");
}
else {
echo date('Y-m-d H:i:s').' [INFO] Moving unzipped files out of temporary directory...'."\n";
$out = exec("mv ./{$_ZDIR}* .; rm -r ./{$_ZDIR}");
if(@unlink('modx.zip')) {
echo date('Y-m-d H:i:s').' [INFO] Removed downloaded zip file...'."\n";
}
echo date('Y-m-d H:i:s').' [INFO] Running into MODX setup...'."\n";
$out = exec("cd setup/; php ./index.php --installmode=new --config={$projectpath}config.xml");
$out = exec("cd {$projectpath}");
echo date('Y-m-d H:i:s').' [INFO] Copying ht.access to .htaccess...'."\n";
copy('ht.access', '.htaccess');
if(@unlink('config.xml')) {
echo date('Y-m-d H:i:s').' [INFO] Removed config XML file...'."\n";
}
// load hooks
loadHooks('install-core');
}
echo "\n\n---------------------------\nCongrats! MODX is installed!\n";
echo "Please visit http://{$projecthost}/manager/ to login.\n";
echo "User: {$adminUser}\n";
echo "Pass: {$adminPassword}\n";
echo "---------------------------\n";