2 //required for normal operation because of recent changes in PHP:
5 //turn off PHP compatibility warnings
6 ini_set("session.bug_compat_warn","off");
9 $dumpfile = "sql/database.sql";
10 $icd9 = "sql/icd9.sql";
11 $conffile = "library/sqlconf.php";
13 $defhost = 'localhost';
14 $state = $_POST["state"];
15 $gaclConfigFile1 = "gacl/gacl.ini.php";
16 $gaclConfigFile2 = "gacl/gacl.class.php";
17 $gaclWritableDirectory = "gacl/admin/templates_c";
18 $gaclSetupScript1 = "./gacl/setup.php";
19 $gaclSetupScript2 = "./acl_setup.php";
20 $writableFileList = array($conffile, $gaclConfigFile1, $gaclConfigFile2);
21 $writableDirList = array($gaclWritableDirectory);
23 include_once($conffile);
27 <TITLE
>OpenEMR Setup Tool
</TITLE
>
28 <LINK REL
=STYLESHEET HREF
="interface/themes/style_blue.css">
32 <span
class="title">OpenEMR Setup
</span
>
37 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
38 echo "It appears that you have register_globals enabled in your php.ini\n" .
39 "configuration file. This causes unacceptable security risks. You must\n" .
40 "turn it off before continuing with installation.\n";
49 <p
>Congratulations
! OpenEMR is now successfully installed
.
52 <li
>Please Edit the
'interface/globals.php' file now to specify the correct
53 URL paths
, and to select a theme
.</li
>
54 <li
>Please make sure that the two folders underneath
55 'openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/'
56 exist
and are writable by the web server
. The two subdirectories are
57 'compiled' and 'cache'.<br
>
58 Try "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled"
60 "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/cache".
61 (If either subdirectory doesn
't exist, create it first then do the chown above).<br>
62 The user name and group of apache may differ depending on your OS, i.e.
63 for Debian they are www-data and www-data.</li>
64 <li>Please restore secure permissions on the configuration files: /openemr/library/sqlconf.php,<br>
65 /openemr/gacl/gacl.ini.php, and /openemr/gacl/gacl.class.php files.</li>
68 In order to take full advantage of the documents capability you
69 must give your web server permissions on the document storage
70 directory. Try "chown apache:apache -R openemrwebroot/documents"
71 and then "chmod g+w openemrwebroot/documents".
72 You must also make sure your PHP installation (normally set in
73 your php.ini file) has "file_uploads enabled", that
74 "upload_max_filesize" is appropriate for your use and that
75 "upload_tmp_dir" is set to a correct value if the default of
76 "/tmp" won't work on your system
.
79 Access
controls (php
-GACL
) are installed
for fine
-grained security
,
80 and can be administered in OpenEMR
's admin->acl menu.
83 There's much information
and many extra tools bundled within the OpenEMR
84 installation directory
. Please refer to openemr
/Documentation
.
85 <br
>Many forms
and other useful scripts can be found at openemr
/contrib
.
88 Reading openemr
/includes
/config
.php
and openemr
/interface/globals
.php is a good
92 To ensure a consistent look
and feel through out the application
93 using
<a href
='http://www.mozilla.org/products/firefox/'>Firefox
</a
>
97 <b
>The initial OpenEMR user is
"<?php echo $iuser; ?>" and the password is
"pass".</b
>
98 You should change this password
!
101 <a href
='./'>Click here to start using OpenEMR
. </a
>
111 $server = $_POST["server"];
112 $port = $_POST["port"];
113 $dbname = $_POST["dbname"];
114 $root = $_POST["root"];
115 $login = $_POST["login"];
116 $pass = $_POST["pass"];
117 $loginhost = $_POST["loginhost"];
118 $rootpass = $_POST["rootpass"];
122 echo "OpenEMR is already configured. If you wish to re-configure the SQL server, edit $conffile, or change the 'config' variable to 0, and re-run this script.<br>\n";
128 echo "<b>Step $state</b><br><br>\n";
129 echo "Now I need to know whether you want me to create the databases on my own or if you have already created the database for me to use. If you are upgrading, you will want to select the latter function. For me to create the databases, you will need to supply the MySQL root password.\n
130 <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>
132 <FORM METHOD='POST'>\n
133 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
134 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
135 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
137 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
141 echo "<b>Step $state</b><br><br>\n";
142 echo "Now you need to supply the MySQL server information.
145 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
146 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
148 <TR><TD><font color='red'>SERVER:</font></TD></TR>
149 <TR><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='server' SIZE='30'><span class='text'>(This is the IP address of the machine running MySQL)</span><br></TD></TR>
150 <TR><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'><span class='text'>(The default port for MySQL is 3306)</span><br></TD></TR>
151 <TR><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'><span class='text'>(This is the name of the OpenEMR database - 'openemr' is the recommended)</span><br></TD></TR>
152 <TR><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'><span class='text'>(This is the name of the OpenEMR login name - 'openemr' is the recommended)</span><br></TD></TR>
153 <TR><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'><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";
155 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
156 echo "<TR><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='loginhost' SIZE='30'><span class='text'>(This is the IP address of the server machine running Apache and PHP - if you are setting up one computer, this is the same as the Server Host above)</span><br></TD></TR>
157 <TR><TD><span class='text'>Name for Root Account: </span></TD><TD><INPUT TYPE='TEXT' VALUE='root' NAME='root' SIZE='30'><span class='text'>(This is name for MySQL root account. For localhost, it is usually ok to leave it 'root'.)</span><br></TD></TR>
158 <TR><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
160 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
161 echo "<TR><TD COLSPAN=2></TD></TR>
162 <TR><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'><span class='text'>(This is the user that will be created for you. It will be an authorized user, so it should be for a Doctor or other Practitioner)</span></TD></TR>
163 <TR><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'><span class='text'>(This is the real name of the initial user.)</span></TD></TR>
164 <TR><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'><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>
168 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
176 echo "<b>Step $state</b><br><br>\n";
177 if ($pass == "" ||
$login == "" ||
!isset($login) ||
!isset($pass)) {
178 echo "ERROR. Please pick a proper username and/or password.<br>\n";
183 echo "Connecting to MySQL Server...\n";
185 if ($server == "localhost")
186 $dbh = mysql_connect("$server","$root","$rootpass");
188 $dbh = mysql_connect("$server:$port","$root","$rootpass");
190 echo "ERROR. Check your login credentials.\n";
191 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
196 echo "Creating database...\n";
198 if (mysql_query("create database $dbname",$dbh) == FALSE) {
199 echo "ERROR. Check your login credentials.\n";
200 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
205 echo "Creating user with permissions for database...\n";
207 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
208 echo "ERROR when granting privileges to the specified user.\n";
209 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
215 echo "Reconnecting as new user...\n";
219 echo "Connecting to MySQL Server...\n";
221 if ($server == "localhost")
222 $dbh = mysql_connect("$server","$login","$pass");
224 $dbh = mysql_connect("$server:$port","$login","$pass");
227 echo "ERROR. Check your login credentials.\n";
228 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
233 echo "Opening database...";
235 if (mysql_select_db("$dbname",$dbh) == FALSE) {
236 echo "ERROR. Check your login credentials.\n";
237 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
244 echo "Creating initial tables...\n";
245 mysql_query("USE $dbname",$dbh);
247 $fd = fopen($dumpfile, 'r');
249 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
256 $line = fgets($fd,1024);
257 $line = rtrim($line);
258 if (substr($line,0,2) == "--") // Kill comments
260 if (substr($line,0,1) == "#") // Kill comments
264 $query = $query.$line; // Check for full query
265 $chr = substr($query,strlen($query)-1,1);
266 if ($chr == ";") { // valid query, execute
267 $query = rtrim($query,";");
268 mysql_query("$query",$dbh);
275 echo "Adding Initial User...\n";
277 $iuser = $_POST["iuser"];
278 $iuname = $_POST["iuname"];
279 $igroup = $_POST["igroup"];
280 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
281 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
282 echo "ERROR. Could not run queries.\n";
283 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
287 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
288 echo "ERROR. Could not run queries.\n";
289 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
295 /* echo "Inserting ICD-9-CM Codes into Database...\n";
297 $fd = fopen($icd9, 'r');
299 echo "ERROR. Could not open dumpfile.\n";
300 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
307 $line = fgets($fd,1024);
308 $line = rtrim($line);
309 if (substr($line,0,2) == "--") // Kill comments
311 if (substr($line,0,1) == "#") // Kill comments
315 $query = $query.$line; // Check for full query
316 $chr = substr($query,strlen($query)-1,1);
317 if ($chr == ";") { // valid query, execute
318 $query = rtrim($query,";");
319 mysql_query("$query",$dbh);
327 echo "\n<br>Next step will ensure the following files or directories are world-writeable:<br>\n";
328 foreach ($writableFileList as $tempFile) {
329 echo " 'openemr/$tempFile' file<br>";
331 foreach ($writableDirList as $tempDir) {
332 echo " 'openemr/$tempDir' directory<br>";
336 <FORM METHOD='POST'>\n
337 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
338 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
339 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
340 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
341 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
342 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
343 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
344 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
346 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
352 echo "<b>Step $state</b><br><br>\n";
353 echo "Checking to ensure files are ready...<br>";
355 //ensure required files and directories are writable before moving on
357 foreach ($writableFileList as $tempFile) {
358 if (is_writable($tempFile)) {
359 echo "'openemr/$tempFile' file is ready.<br>";
362 echo "<br>UNABLE to open configuration file 'openemr/$tempFile' for writing.<br>";
363 echo "(ensure 'openemr/$tempFile' file is world-writeable)<br><br>";
369 foreach ($writableDirList as $tempDir) {
370 if (is_writable($tempDir)) {
371 echo "'openemr/$tempDir' directory is ready.<br>";
374 echo "<br>UNABLE to open directory 'openemr/$tempDir' for writing.<br>";
375 echo "(ensure 'openemr/$tempDir' directory is world-writeable)<br><br>";
380 if ($errorWritable) {
381 echo "You can't proceed until all files are ready.<br>";
382 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>";
385 <FORM METHOD='POST'>\n
386 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
387 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
388 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
389 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
390 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
391 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
392 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
393 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
395 <INPUT TYPE='SUBMIT' VALUE='Check Again'><br></FORM><br>\n";
399 //passed all file tests, now can write sql configuration and configure php-GACL
400 echo "<br>Files are all ready, now writing SQL Configuration to disk and configuring access controls (php-GACL)...<br><br>";
401 echo "Writing SQL Configuration...<br>";
402 @touch
($conffile); // php bug
403 $fd = @fopen
($conffile, 'w');
407 // Referenced from sql.inc
411 $it_died = 0; //fmg: variable keeps running track of any errors
413 fwrite($fd,$string) or $it_died++
;
414 fwrite($fd,"\$host\t= '$host';\n") or $it_died++
;
415 fwrite($fd,"\$port\t= '$port';\n") or $it_died++
;
416 fwrite($fd,"\$login\t= '$login';\n") or $it_died++
;
417 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++
;
418 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++
;
424 $sqlconf["host"]= $host;
425 $sqlconf["port"] = $port;
426 $sqlconf["login"] = $login;
427 $sqlconf["pass"] = $pass;
428 $sqlconf["dbase"] = $dbase;
429 //////////////////////////
430 //////////////////////////
431 //////////////////////////
432 //////DO NOT TOUCH THIS///
433 $config = 1; /////////////
434 //////////////////////////
435 //////////////////////////
436 //////////////////////////
439 ?
><?
// done just for coloring
441 fwrite($fd,$string) or $it_died++
;
443 //it's rather irresponsible to not report errors when writing this file.
445 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
451 echo "Successfully wrote SQL configuration.<BR><br>";
453 echo "Installing and Configuring Access Controls (php-GACL)<br>";
455 //first, edit two gacl config files
457 $data = file($gaclConfigFile1) or die("Could not read ".$gaclConfigFile1." file.");
459 foreach ($data as $line) {
461 if ((strpos($line,"db_host")) === false) {
465 $finalData .= "db_host = \"${host}\"\n";
467 if ((strpos($line,"db_user")) === false) {
471 $finalData .= "db_user = \"${login}\"\n";
473 if ((strpos($line,"db_password")) === false) {
477 $finalData .= "db_password = \"${pass}\"\n";
479 if ((strpos($line,"db_name")) === false) {
483 $finalData .= "db_name = \"${dbname}\"\n";
489 $fd = @fopen
($gaclConfigFile1, 'w') or die("Could not open ".$gaclConfigFile1." file.");
490 fwrite($fd, $finalData);
493 // edit gacl.class.php
494 $data = file($gaclConfigFile2) or die("Could not read ".$gaclConfigFile2." file.");
496 foreach ($data as $line) {
498 if ((strpos($line,"var \$_db_host = ")) === false) {
502 $finalData .= "var \$_db_host = '$host';\n";
504 if ((strpos($line,"var \$_db_user = ")) === false) {
508 $finalData .= "var \$_db_user = '$login';\n";
510 if ((strpos($line,"var \$_db_password = ")) === false) {
514 $finalData .= "var \$_db_password = '$pass';\n";
516 if ((strpos($line,"var \$_db_name = ")) === false) {
520 $finalData .= "var \$_db_name = '$dbname';\n";
526 $fd = @fopen
($gaclConfigFile2, 'w') or die("Could not open ".$gaclConfigFile2." file.");
527 fwrite($fd, $finalData);
530 //second, run gacl config scripts
531 require $gaclSetupScript1;
532 require $gaclSetupScript2;
535 //third, give the administrator user admin priviledges
536 $groupArray = array("Administrators");
537 set_user_aro($groupArray,$iuser,$iuname,"","");
538 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br>";
540 echo "<br><FORM METHOD='POST'>\n
541 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
542 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
544 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
550 echo "Welcome to OpenEMR. This utility will step you through the configuration of OpenEMR for your practice. Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.<br><br>\n";
552 Echo "<p>If you are upgrading from a previous version, please read the README file.<br><br>";
554 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";