Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / setup.php
blob1d044c016b17d2d27631b28909449a3f1ad36e12
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 // Dummy xl function so things needing it will work.
8 function xl($s) {
9 return $s;
12 //turn off PHP compatibility warnings
13 ini_set("session.bug_compat_warn","off");
15 $url = "";
16 $upgrade = 0;
17 $state = $_POST["state"];
19 // Make this true for IPPF.
20 $ippf_specific = false;
22 //If having problems with file and directory permission
23 // checking, then can be manually disabled here.
24 $checkPermissions = "TRUE";
26 //Below section is only for variables that require a path.
27 // The $manualPath variable can be edited by 3rd party
28 // installation scripts to manually set path. (this will
29 // allow straightforward use of this script by 3rd party
30 // installers)
31 $manualPath = "";
32 $dumpfile = $manualPath."sql/database.sql";
33 $translations_dumpfile_utf8 = $manualPath."contrib/util/language_translations/currentLanguage_utf8.sql";
34 $translations_dumpfile_latin1 = $manualPath."contrib/util/language_translations/currentLanguage_utf8.sql";
35 $icd9 = $manualPath."sql/icd9.sql";
36 $conffile = $manualPath."library/sqlconf.php";
37 $conffile2 = $manualPath."interface/globals.php";
38 $docsDirectory = $manualPath."documents";
39 $billingDirectory = $manualPath."edi";
40 $billingDirectory2 = $manualPath."era";
41 $billingLogDirectory = $manualPath."library/freeb";
42 $lettersDirectory = $manualPath."custom/letter_templates";
43 $gaclWritableDirectory = $manualPath."gacl/admin/templates_c";
44 $requiredDirectory1 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
45 $requiredDirectory2 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/cache";
46 $gaclSetupScript1 = $manualPath."gacl/setup.php";
47 $gaclSetupScript2 = $manualPath."acl_setup.php";
49 //These are files and dir checked before install for
50 // correct permissions.
51 // $writableFileList = array($conffile, $conffile2);
52 $writableFileList = array($conffile);
53 $writableDirList = array($docsDirectory, $billingDirectory, $billingDirectory2, $billingLogDirectory, $lettersDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
55 //These are the dumpfiles that are loaded into database
56 // The subsequent array holds the title of dumpfiles
57 $dumpfiles = array($dumpfile);
58 $dumpfilesTitles = array("Main");
60 include_once($conffile);
62 <HTML>
63 <HEAD>
64 <TITLE>OpenEMR Setup Tool</TITLE>
65 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
66 </HEAD>
67 <BODY>
69 <span class="title">OpenEMR Setup</span>
70 <br><br>
71 <span class="text">
73 <?php
74 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
75 echo "It appears that you have register_globals enabled in your php.ini\n" .
76 "configuration file. This causes unacceptable security risks. You must\n" .
77 "turn it off before continuing with installation.\n";
78 exit();
80 ?>
82 <?php
83 if ($state == 7) {
84 $iuser = $_POST["iuser"];
87 <p>Congratulations! OpenEMR is now installed.</p>
89 <ul>
90 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
91 OpenEMR's admin->acl menu.</li>
92 <li>Reading openemr/includes/config.php and openemr/interface/globals.php is a good idea. These files
93 contain many options to choose from including themes.</li>
94 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
95 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
96 <li>To ensure a consistent look and feel through out the application using
97 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> is recommended.</li>
98 <li>The OpenEMR project home page and wiki can be found at <a href = "http://www.oemr.org" target="_blank">http://www.oemr.org</a></li>
99 <li>The OpenEMR forums can be found at <a href = "http://sourceforge.net/projects/openemr" target="_blank">http://sourceforge.net/projects/openemr</a></li>
100 <li>We pursue grants to help fund the future development of OpenEMR. To apply for these grants, we need to estimate how many times this program is installed and how many practices are evaluating or using this software. It would be awesome if you would email us at <a href="mailto:drbowen@openmedsoftware.org">drbowen@openmedsoftware.org</a> if you have installed this software. The more details about your plans with this software, the better, but even just sending us an email stating you just installed it is very helpful.</li>
101 </ul>
103 We recommend you print these instructions for future reference.
104 </p>
106 <b>The initial OpenEMR user is "<?php echo $iuser; ?>" and the password is "pass".</b>
107 You should change this password!
108 </p>
110 If you edited the PHP or Apache configuration files during this installation process, then we recommend you restart your Apache server before following below OpenEMR link.
111 </p>
113 <a href='./'>Click here to start using OpenEMR. </a>
114 </p>
116 <?php
117 exit();
121 <?php
123 $server = $_POST["server"];
124 $port = $_POST["port"];
125 $dbname = $_POST["dbname"];
126 $root = $_POST["root"];
127 $login = $_POST["login"];
128 $pass = $_POST["pass"];
129 $loginhost = $_POST["loginhost"];
130 $collate = $_POST["collate"];
131 $rootpass = $_POST["rootpass"];
132 $iuser = $_POST["iuser"];
133 $iuname = $_POST["iuname"];
134 $igroup = $_POST["igroup"];
135 $inst = $_POST["inst"];
137 /*******************************************************************
138 $openemrBasePath = $_POST["openemrBasePath"];
139 $openemrWebPath = $_POST["openemrWebPath"];
140 *******************************************************************/
142 //END POST VARIABLES
145 if (($config == 1) && ($state < 4)) {
146 echo "OpenEMR has already been installed. If you wish to force re-installation, then edit $conffile(change the 'config' variable to 0), and re-run this script.<br>\n";
148 else {
149 switch ($state) {
151 case 1:
152 echo "<b>Step $state</b><br><br>\n";
153 echo "Now I need to know whether you want me to create the database on my own or if you have already created the database for me to use. For me to create the database, you will need to supply the MySQL root password.\n
154 <span class='title'> <br />NOTE: clicking on \"Continue\" may delete or cause damage to data on your system. Before you continue please backup your data.</span>
155 <br><br>\n
156 <FORM METHOD='POST'>\n
157 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
158 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the database<br>\n
159 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the database<br>\n
160 <br>\n
161 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
162 break;
164 case 2:
165 echo "<b>Step $state</b><br><br>\n";
166 echo "Now you need to supply the MySQL server information and path information. Detailed instructions on each item can be found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.
167 <br><br>\n
168 <FORM METHOD='POST'>
169 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
170 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
171 <TABLE>\n
172 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
173 <TR VALIGN='TOP'><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='localhost' NAME='server' SIZE='30'></TD><TD><span class='text'>(If you run MySQL and Apache/PHP on the same computer, then leave this as 'localhost'. If they are on separate computers, then enter the IP address of the computer running MySQL.)</span><br></TD></TR>
174 <TR VALIGN='TOP'><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'></TD><TD><span class='text'>(This is the MySQL port. The default port for MySQL is 3306.)</span><br></TD></TR>
175 <TR VALIGN='TOP'><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR database in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
176 <TR VALIGN='TOP'><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR login name in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
177 <TR VALIGN='TOP'><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'></TD><TD><span class='text'>(This is the Login Password for when PHP accesses MySQL - it should be at least 8 characters long and composed of both numbers and letters)</span><br></TD></TR>\n";
178 if ($inst != 2) {
179 echo "<TR VALIGN='TOP'><TD><span class='text'>Name for Root Account: </span></TD><TD><INPUT TYPE='TEXT' VALUE='root' NAME='root' SIZE='30'></TD><TD><span class='text'>(This is name for MySQL root account. For localhost, it is usually ok to leave it 'root'.)</span><br></TD></TR>
180 <TR VALIGN='TOP'><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'></TD><TD><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
181 echo "<TR VALIGN='TOP'><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='localhost' NAME='loginhost' SIZE='30'></TD><TD><span class='text'>(If you run Apache/PHP and MySQL on the same computer, then leave this as 'localhost'. If they are on separate computers, then enter the IP address of the computer running Apache/PHP.)</span><br></TD></TR>";
182 echo "<TR VALIGN='TOP'><TD><span class='text'>UTF-8 Collation: </span></TD><TD colspan='2'>" .
183 "<select name='collate'>" .
184 "<option value='utf8_bin' >Bin</option>" .
185 "<option value='utf8_czech_ci' >Czech</option>" .
186 "<option value='utf8_danish_ci' >Danish</option>" .
187 "<option value='utf8_esperanto_ci' >Esperanto</option>" .
188 "<option value='utf8_estonian_ci' >Estonian</option>" .
189 "<option value='utf8_general_ci' selected>General</option>" .
190 "<option value='utf8_hungarian_ci' >Hungarian</option>" .
191 "<option value='utf8_icelandic_ci' >Icelandic</option>" .
192 "<option value='utf8_latvian_ci' >Latvian</option>" .
193 "<option value='utf8_lithuanian_ci'>Lithuanian</option>" .
194 "<option value='utf8_persian_ci' >Persian</option>" .
195 "<option value='utf8_polish_ci' >Polish</option>" .
196 "<option value='utf8_roman_ci' >Roman</option>" .
197 "<option value='utf8_romanian_ci' >Romanian</option>" .
198 "<option value='utf8_slovak_ci' >Slovak</option>" .
199 "<option value='utf8_slovenian_ci' >Slovenian</option>" .
200 "<option value='utf8_spanish2_ci' >Spanish2 (Traditional)</option>" .
201 "<option value='utf8_spanish_ci' >Spanish (Modern)</option>" .
202 "<option value='utf8_swedish_ci' >Swedish</option>" .
203 "<option value='utf8_turkish_ci' >Turkish</option>" .
204 "<option value='utf8_unicode_ci' >Unicode (German, French, Russian, Armenian, Greek)</option>" .
205 "<option value='' >None (Do not force UTF-8)</option>" .
206 "</select>" .
207 "</TD></TR><TR VALIGN='TOP'><TD>&nbsp;</TD><TD colspan='2'><span class='text'>(This is the collation setting for mysql. Leave as 'General' if you are not sure. If the language you are planning to use in OpenEMR is in the menu, then you can select it. Otherwise, just select 'General'.)</span><br></TD></TR>";
209 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
210 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
211 echo "<TR VALIGN='TOP'><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'></TD><TD><span class='text'>(This is the login name of user that will be created for you. Limit this to one word.)</span></TD></TR>
212 <TR VALIGN='TOP'><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'></TD><TD><span class='text'>(This is the real name of the 'initial user'.)</span></TD></TR>
213 <TR VALIGN='TOP'><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'></TD><TD><span class='text'>(This is the group that will be created for your users. This should be the name of your practice.)</span></TD></TR>
215 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
217 /*********************************************************************
218 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR PATHS:</font></TD></TR>";
219 echo "<TR VALIGN='TOP'><TD COLSPAN=3></TD></TR>
220 <TR VALIGN='TOP'><TD><span class='text'>Absolute Path:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='openemrBasePath' VALUE='".realpath('./')."'></TD><TD><span class='text'>(This is the full absolute directory path to openemr. The value here is automatically created, and should not need to be modified. Do not worry about direction of slashes; they will be automatically corrected.)</span></TD></TR>
221 <TR VALIGN='TOP'><TD><span class='text'>Relative HTML Path:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='openemrWebPath' VALUE='/openemr'></TD><TD><span class='text'>(Set this to the relative html path, ie. what you would type into the web browser after the server address to get to OpenEMR. For example, if you type 'http://127.0.0.1/clinic/openemr/ to load OpenEMR, set this to '/clinic/openemr' without the trailing slash. Do not worry about direction of slashes; they will be automatically corrected.)</span></TD></TR>
223 *********************************************************************/
225 echo "</TABLE>
226 <br>
227 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
229 break;
232 case 3:
234 if ($login == "" || !isset($login)) {
235 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
236 echo "Click Back in browser to re-enter.<br>\n";
237 break;
239 if (strpos($iuser, " ")) {
240 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
241 echo "Click Back in browser to re-enter.<br>\n";
242 break;
244 if ($pass == "" || !isset($pass)) {
245 echo "ERROR. Please pick a proper 'Password'.<br>\n";
246 echo "Click Back in browser to re-enter.<br>\n";
247 break;
250 echo "<b>Step $state</b><br><br>\n";
251 echo "Configuring OpenEMR...<br><br>\n";
254 if ($inst != 2) {
255 echo "Connecting to MySQL Server...\n";
256 flush();
257 if ($server == "localhost")
258 $dbh = mysql_connect("$server","$root","$rootpass");
259 else
260 $dbh = mysql_connect("$server:$port","$root","$rootpass");
261 if ($dbh == FALSE) {
262 echo "ERROR. Check your login credentials.\n";
263 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
264 break;
266 else
267 echo "OK.<br>\n";
268 echo "Creating database...\n";
269 flush();
270 $sql = "create database $dbname";
271 if ($collate) {
272 $sql .= " character set utf8 collate $collate";
273 mysql_query("SET NAMES 'utf8'", $dbh);
275 if (mysql_query($sql, $dbh) == FALSE) {
276 echo "ERROR. Check your login credentials.\n";
277 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
278 break;
280 else
281 echo "OK.<br>\n";
282 echo "Creating user with permissions for database...\n";
283 flush();
284 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
285 echo "ERROR when granting privileges to the specified user.\n";
286 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
287 echo "ERROR.\n";
288 break;
290 else
291 echo "OK.<br>\n";
292 echo "Reconnecting as new user...\n";
293 mysql_close($dbh);
295 else
296 echo "Connecting to MySQL Server...\n";
298 if ($server == "localhost")
299 $dbh = mysql_connect("$server","$login","$pass");
300 else
301 $dbh = mysql_connect("$server:$port","$login","$pass");
303 if ($dbh == FALSE) {
304 echo "ERROR. Check your login credentials.\n";
305 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
306 break;
308 else {
309 if ($collate) {
310 mysql_query("SET NAMES 'utf8'", $dbh);
312 echo "OK.<br>\n";
314 echo "Opening database...";
315 flush();
316 if (mysql_select_db("$dbname",$dbh) == FALSE) {
317 echo "ERROR. Check your login credentials.\n";
318 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
319 break;
321 else
322 echo "OK.<br>\n";
323 flush();
324 if ($upgrade != 1) {
326 //select the correct translation dumpfile
327 if ($collate) {
328 array_push($dumpfiles,$translations_dumpfile_utf8);
329 array_push($dumpfilesTitles,"Language Translation (utf8)");
331 else {
332 array_push($dumpfiles,$translations_dumpfile_latin1);
333 array_push($dumpfilesTitles,"Language Translation (latin1)");
336 // Deal with IPPF-specific SQL.
337 if ($ippf_specific) {
338 array_push($dumpfiles, $manualPath . "sql/ippf_layout.sql");
339 array_push($dumpfilesTitles, "IPPF Layout");
342 $dumpfileCounter = 0;
343 foreach ($dumpfiles as $var) {
344 echo "Creating ".$dumpfilesTitles[$dumpfileCounter]." tables...\n";
345 mysql_query("USE $dbname",$dbh);
346 flush();
347 $fd = fopen($var, 'r');
348 if ($fd == FALSE) {
349 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
350 flush();
351 break;
353 $query = "";
354 $line = "";
355 while (!feof ($fd)){
356 $line = fgets($fd,1024);
357 $line = rtrim($line);
358 if (substr($line,0,2) == "--") // Kill comments
359 continue;
360 if (substr($line,0,1) == "#") // Kill comments
361 continue;
362 if ($line == "")
363 continue;
364 $query = $query.$line; // Check for full query
365 $chr = substr($query,strlen($query)-1,1);
366 if ($chr == ";") { // valid query, execute
367 $query = rtrim($query,";");
368 if (!mysql_query($query, $dbh)) {
369 echo "<p>ERROR. Query failed: \"$query\"\n";
370 echo "<br />" . mysql_error() . " (#" . mysql_errno() . ")</p>\n";
372 $query = "";
375 echo "OK<br>\n";
376 fclose($fd);
377 flush();
378 $dumpfileCounter++;
380 echo "Adding Initial User...\n";
381 flush();
382 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
383 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
384 echo "ERROR. Could not run queries.\n";
385 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
386 flush();
387 break;
389 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname, fname, facility_id, calendar, cal_ui) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','',3,1,3)") == FALSE) {
390 echo "ERROR. Could not run queries.\n";
391 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
392 flush();
393 break;
395 echo "OK<br>\n";
396 flush();
398 /* echo "Inserting ICD-9-CM Codes into Database...\n";
399 flush();
400 $fd = fopen($icd9, 'r');
401 if ($fd == FALSE) {
402 echo "ERROR. Could not open dumpfile.\n";
403 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
404 flush();
405 break;
407 $query = "";
408 $line = "";
409 while (!feof ($fd)){
410 $line = fgets($fd,1024);
411 $line = rtrim($line);
412 if (substr($line,0,2) == "--") // Kill comments
413 continue;
414 if (substr($line,0,1) == "#") // Kill comments
415 continue;
416 if ($line == "")
417 continue;
418 $query = $query.$line; // Check for full query
419 $chr = substr($query,strlen($query)-1,1);
420 if ($chr == ";") { // valid query, execute
421 $query = rtrim($query,";");
422 mysql_query("$query",$dbh);
423 $query = "";
426 echo "OK\n";
427 fclose($fd);*/
429 flush();
432 echo "<br>Writing SQL Configuration...<br>";
433 @touch($conffile); // php bug
434 $fd = @fopen($conffile, 'w');
435 $string = "<?php
436 // OpenEMR
437 // MySQL Config
438 // Referenced from sql.inc
442 $it_died = 0; //fmg: variable keeps running track of any errors
444 fwrite($fd,$string) or $it_died++;
445 fwrite($fd,"\$host\t= '$server';\n") or $it_died++;
446 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
447 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
448 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
449 fwrite($fd,"\$dbase\t= '$dbname';\n\n") or $it_died++;
450 fwrite($fd,"//Added ability to disable\n") or $it_died++;
451 fwrite($fd,"//utf8 encoding - bm 05-2009\n") or $it_died++;
452 fwrite($fd,"\$disable_utf8_flag = false;\n") or $it_died++;
454 $string = '
455 $sqlconf = array();
456 $sqlconf["host"]= $host;
457 $sqlconf["port"] = $port;
458 $sqlconf["login"] = $login;
459 $sqlconf["pass"] = $pass;
460 $sqlconf["dbase"] = $dbase;
461 //////////////////////////
462 //////////////////////////
463 //////////////////////////
464 //////DO NOT TOUCH THIS///
465 $config = 1; /////////////
466 //////////////////////////
467 //////////////////////////
468 //////////////////////////
471 ?><?php // done just for coloring
473 fwrite($fd,$string) or $it_died++;
475 //it's rather irresponsible to not report errors when writing this file.
476 if ($it_died != 0) {
477 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
478 flush();
479 break;
481 fclose($fd);
483 echo "Successfully wrote SQL configuration.<BR><br>";
485 /*********************************************************************
486 echo "Writing OpenEMR webserver paths to config file...<br>";
487 //edit interface/globals.php
488 //first, ensure slashes are in correct direction (windows specific fix)
489 $openemrBasePath = str_replace('\\\\', '/', $openemrBasePath);
490 $openemrBasePath = str_replace('\\', '/', $openemrBasePath);
491 $openemrWebPath = str_replace('\\\\', '/', $openemrWebPath);
492 $openemrWebPath = str_replace('\\', '/', $openemrWebPath);
493 //second, edit file (web paths and set UTF8 if pertinent)
494 $data = file($conffile2) or die("Could not read ".$conffile2." file.");
495 $finalData = "";
496 $isCount = 0;
497 foreach ($data as $line) {
498 $isHit = 0;
499 if ((strpos($line,"\$webserver_root = \"")) === false) {
501 else {
502 $isHit = 1;
503 $isCount += 1;
504 $finalData .= "\$webserver_root = \"$openemrBasePath\";\n";
506 if ((strpos($line,"\$web_root = \"")) === false) {
508 else {
509 $isHit = 1;
510 $isCount += 1;
511 $finalData .= "\$web_root = \"$openemrWebPath\";\n";
513 if (!$isHit) {
514 $finalData .= $line;
517 $fd = @fopen($conffile2, 'w') or die("Could not open ".$conffile2." file.");
518 fwrite($fd, $finalData);
519 fclose($fd);
520 if ($isCount == 2) {
521 echo "Successfully wrote OpenEMR webserver paths to config file<br><br>";
523 else {
524 echo "<FONT COLOR='red'>ERROR</FONT> writing openemr webserver root paths to config file ($conffile2). ($isCount)<br><br>\n";
526 *********************************************************************/
528 echo "Writing global configuration defaults...<br>";
529 require_once("library/globals.inc.php");
530 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
531 foreach ($grparr as $fldid => $fldarr) {
532 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
533 if (substr($fldtype, 0, 2) !== 'm_') {
534 $res = mysql_query("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
535 $row = @mysql_fetch_array($res, MYSQL_ASSOC);
536 if (empty($row['count'])) {
537 mysql_query("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
538 "VALUES ( '$fldid', '0', '$flddef' )");
543 echo "Successfully wrote global configuration defaults.<br><br>";
545 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
547 echo "
548 <FORM METHOD='POST'>\n
549 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
550 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
551 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
552 <br>\n
553 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
556 break;
558 case 4:
559 echo "<b>Step $state</b><br><br>\n";
560 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
562 //run gacl config scripts, all sql config data now in sqlconf.php file
563 require $gaclSetupScript1;
564 require $gaclSetupScript2;
565 echo "<br>";
567 //give the administrator user admin priviledges
568 $groupArray = array("Administrators");
569 set_user_aro($groupArray,$iuser,$iuname,"","");
570 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br><br>";
572 echo "Done installing and configuring access controls (php-GACL).<br>";
573 echo "Next step will configure PHP.";
575 echo "<br><FORM METHOD='POST'>\n
576 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
577 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
578 <br>\n
579 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
581 break;
583 case 5:
584 echo "<b>Step $state</b><br><br>\n";
585 echo "Configuration of PHP...<br><br>\n";
586 echo "We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:\n";
587 echo "<ul>";
588 $gotFileFlag = 0;
589 if (version_compare(PHP_VERSION, '5.2.4', '>=')) {
590 $phpINIfile = php_ini_loaded_file();
591 if ($phpINIfile) {
592 echo "<li><font color='green'>Your php.ini file can be found at ".$phpINIfile."</font></li>\n";
593 $gotFileFlag = 1;
596 echo "<li>To ensure proper functioning of OpenEMR you must make sure that settings in php.ini file include \"short_open_tag = On\", \"display_errors = Off\", \"register_globals = Off\", \"magic_quotes_gpc = On\", \"max_execution_time\" set to at least 60, \"max_input_time\" set to at least 90, and \"memory_limit\" set to at least \"128M\".</li>\n";
597 echo "<li>In order to take full advantage of the patient documents capability you must make sure that settings in php.ini file include \"file_uploads = On\", that \"upload_max_filesize\" is appropriate for your use and that \"upload_tmp_dir\" is set to a correct value that will work on your system.</li>\n";
598 if (!$gotFileFlag) {
599 echo "<li>If you are having difficulty finding your php.ini file, then refer to the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual for suggestions.</li>\n";
601 echo "</ul>";
603 echo "<br>We recommend you print these instructions for future reference.<br><br>";
604 echo "Next step will configure Apache web server.";
606 echo "<br><FORM METHOD='POST'>\n
607 <INPUT TYPE='HIDDEN' NAME='state' VALUE='6'>\n
608 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
609 <br>\n
610 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
612 break;
614 case 6:
615 echo "<b>Step $state</b><br><br>\n";
616 echo "Configuration of Apache web server...<br><br>\n";
617 echo "The \"".realpath($docsDirectory)."\", \"".realpath($billingDirectory)."\" and \"".realpath($billingDirectory2)."\" directories contain patient information, and
618 it is important to secure these directories. This can be done by placing pertinent .htaccess
619 files in these directories or by pasting the below to end of your apache configuration file:<br>
620 &nbsp;&nbsp;&lt;Directory ".realpath($docsDirectory)."&gt;<br>
621 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
622 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
623 &nbsp;&nbsp;&lt;/Directory&gt;<br>
624 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory)."&gt;<br>
625 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
626 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
627 &nbsp;&nbsp;&lt;/Directory&gt;<br>
628 &nbsp;&nbsp;&lt;Directory ".realpath($billingDirectory2)."&gt;<br>
629 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
630 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
631 &nbsp;&nbsp;&lt;/Directory&gt;<br><br>";
633 echo "If you are having difficulty finding your apache configuration file, then refer to the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual for suggestions.<br><br>\n";
634 echo "<br>We recommend you print these instructions for future reference.<br><br>";
635 echo "Click 'continue' for further instructions.";
637 echo "<br><FORM METHOD='POST'>\n
638 <INPUT TYPE='HIDDEN' NAME='state' VALUE='7'>\n
639 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
640 <br>\n
641 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
643 break;
645 case 0:
646 default:
647 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
648 echo "<ul><li>Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.</li>\n";
650 echo "<li>Detailed installation instructions can be found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li>\n";
652 Echo "<li>If you are upgrading from a previous version, do NOT use this script. Please read the 'Upgrading' section found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li></ul>";
654 if ($checkPermissions == "TRUE") {
655 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
656 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
657 $errorWritable = 0;
658 foreach ($writableFileList as $tempFile) {
659 if (is_writable($tempFile)) {
660 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
662 else {
663 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
664 echo "(configure file permissions; see below for further instructions)</p>\n";
665 $errorWritable = 1;
668 if ($errorWritable) {
669 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
670 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
671 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
672 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
673 break;
676 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
677 $errorWritable = 0;
678 foreach ($writableDirList as $tempDir) {
679 if (is_writable($tempDir)) {
680 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
682 else {
683 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
684 echo "(configure directory permissions; see below for further instructions)</p>\n";
685 $errorWritable = 1;
688 if ($errorWritable) {
689 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
690 echo "In linux, recommend changing owners of these directories to the web server. For example, in many linux OS's the web server user is 'apache', 'nobody', or 'www-data'. So if 'apache' were the web server user name, could use the command 'chown -R apache:apache directory_name' command.<br>\n";
691 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
692 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
693 break;
696 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
698 else {
699 echo "<br>Click to continue installation.<br>\n";
702 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
709 </span>
711 </BODY>
712 </HTML>